@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

Manage Guild Wars 2 Account

@_saveMessage


@if (_account.GuildWars2AccountId != 0) {
@foreach (GuildWars2Build build in _buildsToShow.OrderBy(b => b.Class).ThenBy(b => b.EliteSpecialization)) { Equipped? equippedBuild = _account.EquippedBuilds.FirstOrDefault(e => e.GuildWars2BuildId == build.GuildWars2BuildId); bool isEquipped = equippedBuild != null; bool canTank = false; if (isEquipped) { canTank = equippedBuild.CanTank; } }
Equipped Tank Build Class Elite Might Quick Alac Heal Power Condition Hybrid Other Random Source
@build.BuildName @build.Class.ToString() @build.EliteSpecialization.ToString() @build.Source

}
@code { [Parameter] public string gw2Id { get; set; } public GuildWars2Account _account; private LiebUser _user; private string _saveMessage = string.Empty; private List _builds; private List _buildsToShow; 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.GetLiebUserGW2AccountOnly(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(); } _builds = GuildWars2BuildService.GetBuilds(); _buildsToShow = _builds; } 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("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.Id); _account = GuildWars2AccountService.GetAccount(_account.GuildWars2AccountId); _saveMessage = "changes saved successfully"; } private void ChangeBuildFilter( ChangeEventArgs e) { if(Enum.TryParse(e.Value?.ToString(),out GuildWars2Class selectedClass)) { _buildsToShow = _builds.Where(b => b.Class == selectedClass).ToList(); } else { _buildsToShow = _builds; } } }