152 lines
No EOL
5.5 KiB
Text
152 lines
No EOL
5.5 KiB
Text
@page "/gw2accountedit"
|
|
@page "/gw2accountedit/{gw2Id}"
|
|
@using Lieb.Data
|
|
@using Lieb.Models
|
|
@using Lieb.Models.GuildWars2
|
|
@using System.ComponentModel.DataAnnotations
|
|
@using System.Security.Claims
|
|
@inject GuildWars2AccountService GuildWars2AccountService
|
|
@inject GuildWars2BuildService GuildWars2BuildService
|
|
@inject UserService UserService
|
|
@inject NavigationManager NavigationManager
|
|
@inject AuthenticationStateProvider AuthenticationStateProvider
|
|
@inject IJSRuntime JsRuntime
|
|
|
|
<h3>ManageGuildWars2Account</h3>
|
|
|
|
<AuthorizeView Context="authorizationContext">
|
|
<Authorized>
|
|
<EditForm Model="@_account" OnValidSubmit="@HandleValidSubmit">
|
|
<DataAnnotationsValidator />
|
|
|
|
<p>@_saveMessage</p>
|
|
<p>
|
|
<label>
|
|
Account name:
|
|
<InputText @bind-Value="_account.AccountName" />
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>
|
|
Api-Key:
|
|
<InputText @bind-Value="_account.ApiKey" />
|
|
</label>
|
|
</p>
|
|
|
|
<br />
|
|
<button type="submit">Save</button>
|
|
<ValidationSummary />
|
|
|
|
</EditForm>
|
|
|
|
@if (_account.GuildWars2AccountId != 0)
|
|
{
|
|
<br />
|
|
<table>
|
|
<tr>
|
|
<th>Equipped</th>
|
|
<th>can Tank</th>
|
|
<th>Build</th>
|
|
<th>Class</th>
|
|
<th>Elite</th>
|
|
<th>Might</th>
|
|
<th>Heal</th>
|
|
<th>Quick</th>
|
|
<th>Alac</th>
|
|
</tr>
|
|
@foreach (GuildWars2Build build in GuildWars2BuildService.GetBuilds())
|
|
{
|
|
Equipped? equippedBuild = _account.EquippedBuilds.FirstOrDefault(e => e.GuildWars2BuildId == build.GuildWars2BuildId);
|
|
bool isEquipped = equippedBuild != null;
|
|
bool canTank = false;
|
|
if (isEquipped)
|
|
{
|
|
canTank = equippedBuild.CanTank;
|
|
}
|
|
|
|
<tr>
|
|
<td><input type="checkbox" checked="@isEquipped" @onchange="args => EquippedStatusChanged(build.GuildWars2BuildId, args)" /></td>
|
|
<td><input type="checkbox" checked="@canTank" disabled="@(!isEquipped)" @onchange="args => TankingStatusChanged(build.GuildWars2BuildId, args)" /></td>
|
|
<td>@build.BuildName</td>
|
|
<td>@build.Class.ToString()</td>
|
|
<td>@build.EliteSpecialization.ToString()</td>
|
|
<td><input type="checkbox" checked="@(build.Might)" disabled="true" /></td>
|
|
<td><input type="checkbox" checked="@(build.Heal)" disabled="true" /></td>
|
|
<td><input type="checkbox" checked="@(build.Quickness)" disabled="true" /></td>
|
|
<td><input type="checkbox" checked="@(build.Alacrity)" disabled="true" /></td>
|
|
</tr>
|
|
}
|
|
</table>
|
|
|
|
<br/>
|
|
<button type=button @onclick="() => DeleteAccountClicked()">Delete Account</button>
|
|
}
|
|
|
|
</Authorized>
|
|
</AuthorizeView>
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
|
public string gw2Id { get; set; }
|
|
|
|
public GuildWars2Account _account;
|
|
|
|
private LiebUser _user;
|
|
|
|
private string _saveMessage = string.Empty;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
var authState = await AuthenticationStateProvider.GetAuthenticationStateAsync();
|
|
ulong discordId = ulong.Parse(authState.User.Claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value);
|
|
_user = UserService.GetLiebUserSmall(discordId);
|
|
|
|
if(!string.IsNullOrEmpty(gw2Id) && int.TryParse(gw2Id, out int parsedId) && _user.GuildWars2Accounts.Where(a => a.GuildWars2AccountId == parsedId).Any())
|
|
{
|
|
_account = GuildWars2AccountService.GetAccount(parsedId);
|
|
}
|
|
else
|
|
{
|
|
_account = new GuildWars2Account();
|
|
}
|
|
}
|
|
|
|
async Task EquippedStatusChanged(int buildId, ChangeEventArgs args)
|
|
{
|
|
bool isEquipped = bool.Parse(args.Value.ToString());
|
|
if(isEquipped)
|
|
{
|
|
await GuildWars2AccountService.AddBuild(_account.GuildWars2AccountId, buildId);
|
|
}
|
|
else
|
|
{
|
|
await GuildWars2AccountService.RemoveBuild(_account.GuildWars2AccountId, buildId);
|
|
}
|
|
_account = GuildWars2AccountService.GetAccount(_account.GuildWars2AccountId);
|
|
}
|
|
|
|
async Task TankingStatusChanged(int buildId, ChangeEventArgs args)
|
|
{
|
|
bool canTank = bool.Parse(args.Value.ToString());
|
|
await GuildWars2AccountService.ChangeTankStatus(_account.GuildWars2AccountId, buildId, canTank);
|
|
}
|
|
|
|
async Task DeleteAccountClicked()
|
|
{
|
|
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete this Account?\nThis will sign you off in every raid in which you are signed up with this account.");
|
|
if (confirmed)
|
|
{
|
|
await GuildWars2AccountService.DeleteAccount(_account.GuildWars2AccountId);
|
|
NavigationManager.NavigateTo("accountedit");
|
|
}
|
|
}
|
|
|
|
private async Task HandleValidSubmit()
|
|
{
|
|
await GuildWars2AccountService.AddOrEditAccount(_account, _user.LiebUserId);
|
|
_account = GuildWars2AccountService.GetAccount(_account.GuildWars2AccountId);
|
|
_saveMessage = "changes saved successfully";
|
|
}
|
|
} |