From a84cba196b0bada4abbf2ba869ee3abe62c666e5 Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Sun, 4 Dec 2022 12:59:36 +0100 Subject: [PATCH] deleting a GW2Account now updates the discord message --- Lieb/Data/GuildWars2AccountService.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Lieb/Data/GuildWars2AccountService.cs b/Lieb/Data/GuildWars2AccountService.cs index 8b49ae4..1595a51 100644 --- a/Lieb/Data/GuildWars2AccountService.cs +++ b/Lieb/Data/GuildWars2AccountService.cs @@ -1,5 +1,6 @@ using Lieb.Models; using Lieb.Models.GuildWars2; +using Lieb.Models.GuildWars2.Raid; using Microsoft.EntityFrameworkCore; namespace Lieb.Data @@ -64,7 +65,9 @@ namespace Lieb.Data if (account != null) { context.Equipped.RemoveRange(account.EquippedBuilds); - context.RaidSignUps.RemoveRange(context.RaidSignUps.Where(s => s.GuildWars2AccountId == accountId)); + IEnumerable signUpsToDelete = context.RaidSignUps.Where(s => s.GuildWars2AccountId == accountId); + HashSet raidsToUpdate = signUpsToDelete.Select(s => s.RaidId).ToHashSet(); + context.RaidSignUps.RemoveRange(signUpsToDelete); await context.SaveChangesAsync(); context.GuildWars2Accounts.Remove(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 _discordService.RenameUser(user.Id, user.Name, newMain.AccountName); } + foreach(int raidId in raidsToUpdate) + { + await _discordService.PostRaidMessage(raidId); + } } }