Added delete user button
This commit is contained in:
parent
ce405a3e36
commit
26dd595057
2 changed files with 38 additions and 1 deletions
|
@ -9,11 +9,13 @@ namespace Lieb.Data
|
||||||
{
|
{
|
||||||
private readonly IDbContextFactory<LiebContext> _contextFactory;
|
private readonly IDbContextFactory<LiebContext> _contextFactory;
|
||||||
private readonly DiscordService _discordService;
|
private readonly DiscordService _discordService;
|
||||||
|
private readonly GuildWars2AccountService _guildWars2AccountService;
|
||||||
|
|
||||||
public UserService(IDbContextFactory<LiebContext> contextFactory, DiscordService discordService)
|
public UserService(IDbContextFactory<LiebContext> contextFactory, DiscordService discordService, GuildWars2AccountService guildWars2AccountService)
|
||||||
{
|
{
|
||||||
_contextFactory = contextFactory;
|
_contextFactory = contextFactory;
|
||||||
_discordService = discordService;
|
_discordService = discordService;
|
||||||
|
_guildWars2AccountService = guildWars2AccountService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<LiebUser> GetLiebUsers()
|
public List<LiebUser> GetLiebUsers()
|
||||||
|
@ -101,6 +103,21 @@ namespace Lieb.Data
|
||||||
await _discordService.RenameUser(user.Id, user.Name, GetMainAccount(user.Id).AccountName);
|
await _discordService.RenameUser(user.Id, user.Name, GetMainAccount(user.Id).AccountName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async Task DeleteUser(LiebUser user)
|
||||||
|
{
|
||||||
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
|
||||||
|
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));
|
||||||
|
context.Remove(user);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
public async Task UpdateBannedUntil(ulong userId, DateTime? date)
|
public async Task UpdateBannedUntil(ulong userId, DateTime? date)
|
||||||
{
|
{
|
||||||
using var context = _contextFactory.CreateDbContext();
|
using var context = _contextFactory.CreateDbContext();
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
@inject UserService UserService
|
@inject UserService UserService
|
||||||
@inject NavigationManager NavigationManager
|
@inject NavigationManager NavigationManager
|
||||||
@inject AuthenticationStateProvider AuthenticationStateProvider
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
||||||
|
@inject IJSRuntime JsRuntime
|
||||||
|
|
||||||
<h3>Manage Account</h3>
|
<h3>Manage Account</h3>
|
||||||
|
|
||||||
|
@ -71,6 +72,12 @@
|
||||||
<br />
|
<br />
|
||||||
<button type="submit">Save</button>
|
<button type="submit">Save</button>
|
||||||
<ValidationSummary />
|
<ValidationSummary />
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<br/>
|
||||||
|
<a href="Account/Logout" class="loginText" @onclick="() => DeleteAccountClicked()">Delete Account</a>
|
||||||
</EditForm>
|
</EditForm>
|
||||||
</Authorized>
|
</Authorized>
|
||||||
</AuthorizeView>
|
</AuthorizeView>
|
||||||
|
@ -99,4 +106,17 @@
|
||||||
await UserService.EditUser(_user);
|
await UserService.EditUser(_user);
|
||||||
_saveMessage = "changes saved successfully";
|
_saveMessage = "changes saved successfully";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async Task DeleteAccountClicked()
|
||||||
|
{
|
||||||
|
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");
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue