fixed deleting the user

This commit is contained in:
Sarah Faey 2022-12-01 23:30:46 +01:00
parent 26780fae6e
commit f9e05ab545
2 changed files with 4 additions and 10 deletions

View file

@ -103,17 +103,15 @@ namespace Lieb.Data
await _discordService.RenameUser(user.Id, user.Name, GetMainAccount(user.Id).AccountName);
}
public async Task DeleteUser(LiebUser user)
public async Task DeleteUser(ulong userId)
{
using var context = _contextFactory.CreateDbContext();
LiebUser user = GetLiebUser(userId);
foreach(GuildWars2Account account in user.GuildWars2Accounts)
{
await _guildWars2AccountService.DeleteAccount(account.GuildWars2AccountId);
}
context.RaidLogs.RemoveRange(context.RaidLogs.Where(r => r.UserId == user.Id).ToList());
context.RaidSignUps.RemoveRange(context.RaidSignUps.Where(r => r.LiebUserId == user.Id));
context.RoleAssignments.RemoveRange(context.RoleAssignments.Where(r => r.LiebUserId == user.Id));
user.GuildWars2Accounts.Clear();
context.Remove(user);
await context.SaveChangesAsync();
}

View file

@ -112,11 +112,7 @@
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete this Website Account?\nThis will sign you off in every raid in which you are signed up.");
if (confirmed)
{
await UserService.DeleteUser(_user);
}
else
{
NavigationManager.NavigateTo("accountedit");
await UserService.DeleteUser(_user.Id);
}
}
}