89 lines
3.2 KiB
Plaintext
89 lines
3.2 KiB
Plaintext
@page "/pokemonsleep/add-new-pokemon"
|
|
@inject IPokemonService PokemonService
|
|
@inject NavigationManager Navigation
|
|
|
|
<h2>Add New Pokémon</h2>
|
|
|
|
@if (isSubmitting)
|
|
{
|
|
<p><em>Submitting...</em></p>
|
|
}
|
|
else
|
|
{
|
|
<div class="card shadow border-0 mt-4" style="margin: auto; width: 900px; max-width: 60%; ">
|
|
<EditForm Model="NewPokemon" OnValidSubmit="HandleSubmit">
|
|
<DataAnnotationsValidator />
|
|
<div class="mb-3">
|
|
<label for="PokemonName" class="form-label">Pokémon Name</label>
|
|
<InputText id="PokemonName" @bind-Value="NewPokemon.PokemonName" class="form-control" required />
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="PokemonId" class="form-label">Pokédex ID</label>
|
|
<InputNumber id="PokemonId" @bind-Value="NewPokemon.PokemonId" class="form-control" required />
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="IsVariation" class="form-label">Variation?</label>
|
|
<InputCheckbox id="IsVariation" @bind-Value="NewPokemon.IsVariation" @onclick="onDisable" class="form-control" required />
|
|
</div>
|
|
<div class="mb-3">
|
|
<label for="VariationName" class="form-label">What Variant? (Alolan, Paldean)</label>
|
|
<InputText disabled="@ToggleVariationName" id="VariationName" @bind-Value="NewPokemon.VariationName" class="form-control" required />
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="SleepType" class="form-label">Sleep Type</label>
|
|
<InputSelect id="SleepType" @bind-Value="NewPokemon.SleepType" class="form-select">
|
|
<option value="Dozing">Dozing</option>
|
|
<option value="Snoozing">Snoozing</option>
|
|
<option value="Slumbering">Slumbering</option>
|
|
</InputSelect>
|
|
</div>
|
|
|
|
<div class="mb-3">
|
|
<label for="Speciality" class="form-label">Specialty</label>
|
|
<InputSelect id="SleepType" @bind-Value="NewPokemon.Speciality" class="form-select">
|
|
<option value="Berries">Berries</option>
|
|
<option value="Ingredients">Ingredients</option>
|
|
<option value="Skills">Skills</option>
|
|
</InputSelect>
|
|
</div>
|
|
|
|
<button type="submit" class="btn btn-primary">Add Pokémon</button>
|
|
<button type="button" class="btn btn-secondary" @onclick="Cancel">Cancel</button>
|
|
</EditForm>
|
|
</div>
|
|
}
|
|
|
|
@code {
|
|
private Pokemon NewPokemon = new Pokemon
|
|
{
|
|
PokemonId = 0, // Or any default ID logic
|
|
PokemonName = string.Empty, // Required fields cannot be null
|
|
SleepType = string.Empty,
|
|
Speciality = string.Empty,
|
|
IsVariation = false
|
|
};
|
|
private bool isSubmitting = false;
|
|
|
|
private bool ToggleVariationName { get; set; }
|
|
|
|
private void onDisable()
|
|
{
|
|
this.ToggleVariationName = true;
|
|
}
|
|
private async Task HandleSubmit()
|
|
{
|
|
isSubmitting = true;
|
|
await PokemonService.AddPokemonAsync(NewPokemon);
|
|
isSubmitting = false;
|
|
Navigation.NavigateTo("/pokemonsleep");
|
|
}
|
|
|
|
protected void Cancel(MouseEventArgs e)
|
|
{
|
|
Console.WriteLine("Testing in Cancel");
|
|
Navigation.NavigateTo("/pokemonsleep");
|
|
}
|
|
|
|
} |