128 lines
3.7 KiB
Text
128 lines
3.7 KiB
Text
@page "/buildedit"
|
|
@page "/buildedit/{buildId}"
|
|
@using Lieb.Data
|
|
@using Lieb.Models.GuildWars2
|
|
@using System.ComponentModel.DataAnnotations
|
|
@inject GuildWars2BuildService GuildWars2BuildService
|
|
@inject NavigationManager NavigationManager
|
|
@inject IJSRuntime JsRuntime
|
|
|
|
|
|
<h3>BuildEdit</h3>
|
|
|
|
<AuthorizeView Policy="@Constants.Roles.Admin" Context="authorizationContext">
|
|
<EditForm Model="@_build" OnValidSubmit="@HandleValidSubmit">
|
|
<DataAnnotationsValidator />
|
|
<ValidationSummary />
|
|
|
|
<p>
|
|
<label>
|
|
Build name:
|
|
<InputText @bind-Value="_build.BuildName" />
|
|
</label>
|
|
</p>
|
|
|
|
<p>
|
|
<label>
|
|
<InputCheckbox @bind-Value="_hasMight" />
|
|
Might
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>
|
|
<InputCheckbox @bind-Value="_hasHeal" />
|
|
Heal
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>
|
|
<InputCheckbox @bind-Value="_hasQuickness" />
|
|
Quickness
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>
|
|
<InputCheckbox @bind-Value="_hasAlacrity" />
|
|
Alacrity
|
|
</label>
|
|
</p>
|
|
|
|
<p>
|
|
<label>
|
|
Class:
|
|
<InputSelect @bind-Value="_build.Class">
|
|
@foreach(GuildWars2Class gw2Class in Enum.GetValues(typeof(GuildWars2Class)))
|
|
{
|
|
<option value="@gw2Class">@gw2Class.ToString()</option>
|
|
}
|
|
</InputSelect>
|
|
</label>
|
|
</p>
|
|
<p>
|
|
<label>
|
|
Elite specialization:
|
|
<InputSelect @bind-Value="_build.EliteSpecialization">
|
|
@foreach(EliteSpecialization gw2EliteSpec in Enum.GetValues(typeof(EliteSpecialization)))
|
|
{
|
|
<option value="@gw2EliteSpec">@gw2EliteSpec.ToString()</option>
|
|
}
|
|
</InputSelect>
|
|
</label>
|
|
</p>
|
|
<button type="submit">Submit</button>
|
|
|
|
</EditForm>
|
|
<br/>
|
|
<button type=button @onclick="() => DeleteBuildClicked()">Delete Build</button>
|
|
</AuthorizeView>
|
|
|
|
|
|
@code {
|
|
|
|
[Parameter]
|
|
public string buildId { get; set; }
|
|
|
|
public GuildWars2Build _build;
|
|
|
|
private bool _hasMight;
|
|
private bool _hasHeal;
|
|
private bool _hasQuickness;
|
|
private bool _hasAlacrity;
|
|
|
|
protected override async Task OnInitializedAsync()
|
|
{
|
|
if(!string.IsNullOrEmpty(buildId) && int.TryParse(buildId, out int parsedId))
|
|
{
|
|
_build = GuildWars2BuildService.GetBuild(parsedId);
|
|
_hasMight = _build.Might > 0;
|
|
_hasHeal = _build.Heal > 0;
|
|
_hasQuickness = _build.Quickness > 0;
|
|
_hasAlacrity = _build.Alacrity > 0;
|
|
}
|
|
else
|
|
{
|
|
_build = new GuildWars2Build();
|
|
}
|
|
}
|
|
|
|
async Task DeleteBuildClicked()
|
|
{
|
|
bool confirmed = await JsRuntime.InvokeAsync<bool>("confirm", "Are you sure you want to delete this Build?");
|
|
if (confirmed)
|
|
{
|
|
await GuildWars2BuildService.DeleteBuild(_build.GuildWars2BuildId);
|
|
NavigationManager.NavigateTo("buildoverview");
|
|
}
|
|
}
|
|
|
|
private async Task HandleValidSubmit()
|
|
{
|
|
_build.Might = _hasMight ? (short)5 : (short)0;
|
|
_build.Heal = _hasHeal ? (short)5 : (short)0;
|
|
_build.Quickness = _hasQuickness ? (short)5 : (short)0;
|
|
_build.Alacrity = _hasAlacrity ? (short)5 : (short)0;
|
|
|
|
await GuildWars2BuildService.AddOrEditBuild(_build);
|
|
NavigationManager.NavigateTo("buildoverview");
|
|
}
|
|
}
|