deleting a GW2Account now updates the discord message

This commit is contained in:
Sarah Faey 2022-12-04 12:59:36 +01:00
parent 21ac2db1cd
commit a84cba196b

View file

@ -1,5 +1,6 @@
using Lieb.Models; using Lieb.Models;
using Lieb.Models.GuildWars2; using Lieb.Models.GuildWars2;
using Lieb.Models.GuildWars2.Raid;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
namespace Lieb.Data namespace Lieb.Data
@ -64,7 +65,9 @@ namespace Lieb.Data
if (account != null) if (account != null)
{ {
context.Equipped.RemoveRange(account.EquippedBuilds); context.Equipped.RemoveRange(account.EquippedBuilds);
context.RaidSignUps.RemoveRange(context.RaidSignUps.Where(s => s.GuildWars2AccountId == accountId)); IEnumerable<RaidSignUp> signUpsToDelete = context.RaidSignUps.Where(s => s.GuildWars2AccountId == accountId);
HashSet<int> raidsToUpdate = signUpsToDelete.Select(s => s.RaidId).ToHashSet();
context.RaidSignUps.RemoveRange(signUpsToDelete);
await context.SaveChangesAsync(); await context.SaveChangesAsync();
context.GuildWars2Accounts.Remove(account); context.GuildWars2Accounts.Remove(account);
LiebUser? user = context.LiebUsers.Include(u => u.GuildWars2Accounts).FirstOrDefault(u => u.GuildWars2Accounts.Contains(account)); LiebUser? user = context.LiebUsers.Include(u => u.GuildWars2Accounts).FirstOrDefault(u => u.GuildWars2Accounts.Contains(account));
@ -76,6 +79,10 @@ namespace Lieb.Data
await context.SaveChangesAsync(); await context.SaveChangesAsync();
await _discordService.RenameUser(user.Id, user.Name, newMain.AccountName); await _discordService.RenameUser(user.Id, user.Name, newMain.AccountName);
} }
foreach(int raidId in raidsToUpdate)
{
await _discordService.PostRaidMessage(raidId);
}
} }
} }