exciting-aftermath/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor

146 lines
6.1 KiB
Plaintext

@page "/pokemonsleep"
@inject IPokemonService PokemonService
@attribute [StreamRendering]
<PageTitle>Pokemon Sleep</PageTitle>
<h1>Pokemon Sleep</h1>
@if (pokemons == null)
{
<p><em>Loading...</em></p>
}
else
{
<div class="card shadow border-0 mt-4" style="margin: auto; width: 900px; max-width: 60%; ">
<div class="card-header bg-secondary bg-gradient ml-0 py-3">
<div class="row">
<div class="col-12 text-center">
<h1 class="text-info">Available Pokemon</h1>
</div>
</div>
</div>
<div class="card-body p-4">
<div class="row pb-3">
<div class="col-6">
</div>
<div class="col-6 text-end">
<!--
<button @onclick="ShowCreateForm" class="btn btn-outline-primary">
<i class="bi bi-plus-square"></i> Add New Pokemon
</button>
-->
<NavLink class="btn btn-outline-primary" href="pokemonsleep/add-new-pokemon">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-plus-circle-fill" viewBox="0 0 16 16">
<path d="M16 8A8 8 0 1 1 0 8a8 8 0 0 1 16 0M8.5 4.5a.5.5 0 0 0-1 0v3h-3a.5.5 0 0 0 0 1h3v3a.5.5 0 0 0 1 0v-3h3a.5.5 0 0 0 0-1h-3z" />
</svg> Add New Pokemon
</NavLink>
</div>
</div>
<table class="table">
<thead>
<tr>
<th scope="col" style="width: 50%;"></th>
<th scope="col">#</th>
<th scope="col">Pokemon</th>
<th scope="col">Sleep Type</th>
<th scope="col" style="padding-right: 30px;">Speciality</th>
<th scope="col"></th>
</tr>
</thead>
<tbody>
@foreach (var pokemon in pokemons)
{
<tr style=" text-align: center; margin:0; padding: 0;">
@if (pokemon.IsVariation)
{
@if (pokemon.VariationName == "Alolan")
{
string URL = $"/pokemon_images/normal/{pokemon.PokemonId}-{pokemon.VariationName.ToLower()}{pokemon.PokemonName.ToLower()}.png";
string ShinyURL = $"/pokemon_images/shiny/{pokemon.PokemonId}-{pokemon.VariationName.ToLower()}{pokemon.PokemonName.ToLower()}.png";
<td>
<img style=" width: 90px; height: 90px; " src=@URL />
<img style=" width: 90px; height: 90px; " src=@ShinyURL />
</td>
}
@if (pokemon.VariationName == "Paldean")
{
string URL = $"/pokemon_images/normal/{pokemon.PokemonId}-{pokemon.VariationName.ToLower()}{pokemon.PokemonName.ToLower()}.png";
string ShinyURL = $"/pokemon_images/shiny/{pokemon.PokemonId}-{pokemon.VariationName.ToLower()}{pokemon.PokemonName.ToLower()}.png";
<td>
<img style=" width: 90px; height: 90px; " src=@URL />
<img style=" width: 90px; height: 90px; " src=@ShinyURL />
</td>
}
}
else // Base Case
{
string URL = $"/pokemon_images/normal/{pokemon.PokemonId}.png"; ;
string ShinyURL = $"/pokemon_images/shiny/{pokemon.PokemonId}.png";
<td>
<img style=" width: 90px; height: 90px; " src=@URL />
<img style=" width: 90px; height: 90px; " src=@ShinyURL />
</td>
}
<th scope="row">@pokemon.PokemonId</th>
@if (pokemon.IsVariation)
{
@if (pokemon.VariationName == "Alolan")
{
<td> Alolan @pokemon.PokemonName</td>
}
@if (pokemon.VariationName == "Paldean")
{
<td> Paldean @pokemon.PokemonName</td>
}
}
else // Base Case
{
<td> @pokemon.PokemonName</td>
}
<td>@pokemon.SleepType</td>
<td style="padding-right: 30px;">@pokemon.Speciality</td>
<td>
<a asp-controller="Pokemon" asp-action="PokemonDelete" asp-route-Id="@pokemon.Id" class="btn btn-danger">
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-trash" viewBox="0 0 16 16">
<path d="M5.5 5.5A.5.5 0 0 1 6 6v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m2.5 0a.5.5 0 0 1 .5.5v6a.5.5 0 0 1-1 0V6a.5.5 0 0 1 .5-.5m3 .5a.5.5 0 0 0-1 0v6a.5.5 0 0 0 1 0z" />
<path d="M14.5 3a1 1 0 0 1-1 1H13v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V4h-.5a1 1 0 0 1-1-1V2a1 1 0 0 1 1-1H6a1 1 0 0 1 1-1h2a1 1 0 0 1 1 1h3.5a1 1 0 0 1 1 1zM4.118 4 4 4.059V13a1 1 0 0 0 1 1h6a1 1 0 0 0 1-1V4.059L11.882 4zM2.5 3h11V2h-11z" />
</svg>
</a>
</td>
</tr>
}
</tbody>
</table>
</div>
</div>
}
@code {
private List<Pokemon> pokemons = new List<Pokemon>();
private bool showForm = true;
protected override async Task OnInitializedAsync()
{
var result = await PokemonService.GetAllPokemonAsync();
if (result is not null)
{
pokemons = result;
}
}
}