diff --git a/Portfolio.Application/Services/PokemonService/IPokemonService.cs b/Portfolio.Application/Services/PokemonService/IPokemonService.cs index 1cb4a16..a53b3e2 100644 --- a/Portfolio.Application/Services/PokemonService/IPokemonService.cs +++ b/Portfolio.Application/Services/PokemonService/IPokemonService.cs @@ -10,5 +10,6 @@ namespace Portfolio.Application.Services.PokemonService public interface IPokemonService { Task> GetAllPokemonAsync(); + Task AddPokemonAsync(Pokemon pokemon); } } diff --git a/Portfolio.Application/Services/PokemonService/PokemonService.cs b/Portfolio.Application/Services/PokemonService/PokemonService.cs index 7258bec..6f9e8e9 100644 --- a/Portfolio.Application/Services/PokemonService/PokemonService.cs +++ b/Portfolio.Application/Services/PokemonService/PokemonService.cs @@ -3,6 +3,7 @@ using Portfolio.Domain.Features.Pokemon; using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading.Tasks; @@ -16,72 +17,16 @@ namespace Portfolio.Application.Services.PokemonService { _pokemonRepository = pokemonRepository; } + + public async Task AddPokemonAsync(Pokemon pokemon) + { + await _pokemonRepository.AddPokemonAsync(pokemon); + } + public async Task> GetAllPokemonAsync() { return await _pokemonRepository.GetAllPokemonsAsync(); - //return new List() { - // new Pokemon - // { - // PokemonId = 1, - // PokemonName = "Bulbasaur", - // SleepType = "Dozing", - // Speciality = "Ingredients" - - // }, - // new Pokemon - // { - // PokemonId = 2, - // PokemonName = "Ivysaur", - // SleepType = "Dozing", - // Speciality = "Ingredients" - - // }, - // new Pokemon - // { - // PokemonId = 3, - // PokemonName = "Venasaur", - // SleepType = "Dozing", - // Speciality = "Ingredients" - - // }, - // new Pokemon - // { - // PokemonId = 37, - // PokemonName = "Vulpix", - // SleepType = "Snoozing", - // Speciality = "Berries" - - // }, - // new Pokemon - // { - // PokemonId = 38, - // PokemonName = "Ninetails", - // SleepType = "Snoozing", - // Speciality = "Berries" - - // }, - // new Pokemon - // { - // PokemonId = 37, - // PokemonName = "Vulpix", - // IsVariation = true, - // VariationName = "Alolan", - // SleepType = "Slumbering", - // Speciality = "Berries" - - // }, - // new Pokemon - // { - // PokemonId = 38, - // PokemonName = "Ninetails", - // IsVariation = true, - // VariationName = "Alolan", - // SleepType = "Slumbering", - // Speciality = "Berries" - - // }, - //}; } } } diff --git a/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs b/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs index 48c89af..bea253d 100644 --- a/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs +++ b/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs @@ -9,5 +9,6 @@ namespace Portfolio.Domain.Features.Pokemon public interface IPokemonRepository { Task> GetAllPokemonsAsync(); + Task AddPokemonAsync(Pokemon pokemon); } } diff --git a/Portfolio.Domain/Features/Pokemon/Pokemon.cs b/Portfolio.Domain/Features/Pokemon/Pokemon.cs index 3d64e51..fc6c7e4 100644 --- a/Portfolio.Domain/Features/Pokemon/Pokemon.cs +++ b/Portfolio.Domain/Features/Pokemon/Pokemon.cs @@ -17,4 +17,5 @@ namespace Portfolio.Domain.Features.Pokemon public required string Speciality { get; set; } } + } diff --git a/Portfolio.Infrastructure/Repositories/PokemonRepository.cs b/Portfolio.Infrastructure/Repositories/PokemonRepository.cs index ac893cf..52149de 100644 --- a/Portfolio.Infrastructure/Repositories/PokemonRepository.cs +++ b/Portfolio.Infrastructure/Repositories/PokemonRepository.cs @@ -21,5 +21,10 @@ namespace Portfolio.Infrastructure.Repositories { return await _context.Pokemons.ToListAsync(); } + public async Task AddPokemonAsync(Pokemon pokemon) + { + _context.Pokemons.Add(pokemon); + await _context.SaveChangesAsync(); + } } } diff --git a/Portfolio.WebUI.Server/Components/Pages/PokemonCreate.razor b/Portfolio.WebUI.Server/Components/Pages/PokemonCreate.razor new file mode 100644 index 0000000..7ee699d --- /dev/null +++ b/Portfolio.WebUI.Server/Components/Pages/PokemonCreate.razor @@ -0,0 +1,89 @@ +@page "/pokemonsleep/add-new-pokemon" +@inject IPokemonService PokemonService +@inject NavigationManager Navigation + +

Add New Pokémon

+ +@if (isSubmitting) +{ +

Submitting...

+} +else +{ +
+ + +
+ + +
+ +
+ + +
+
+ + +
+
+ + +
+ +
+ + + + + + +
+ +
+ + + + + + +
+ + + +
+
+} + +@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"); + } + +} \ No newline at end of file diff --git a/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor b/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor index 80d5e73..097ef86 100644 --- a/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor +++ b/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor @@ -1,4 +1,5 @@ @page "/pokemonsleep" + @inject IPokemonService PokemonService @attribute [StreamRendering] @@ -6,16 +7,14 @@ Pokemon Sleep

Pokemon Sleep

- @if (pokemons == null) {

Loading...

} else { -
- -
+
+

Available Pokemon

@@ -27,11 +26,21 @@ else
- Add New Pokemon - + + + + + Add New Pokemon +
- + + +
@@ -41,45 +50,89 @@ else - - - @foreach (var pokemon in pokemons) - { - string URL = "https://www.serebii.net/pokemonsleep/pokemon/" + pokemon.Id + ".png"; - string ShinyURL = "https://www.serebii.net/pokemonsleep/pokemon/shiny/" + pokemon.Id + ".png"; - + + + @foreach (var pokemon in pokemons) + { - - - - - - - - - } - -
Speciality
- - - @pokemon.Id @pokemon.PokemonName@pokemon.SleepType@pokemon.Speciality - - - -
+ @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"; + + + + + } + @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"; + + + + + } + } + else // Base Case + { + string URL = $"/pokemon_images/normal/{pokemon.PokemonId}.png"; ; + string ShinyURL = $"/pokemon_images/shiny/{pokemon.PokemonId}.png"; + + + + + } -
+ @pokemon.PokemonId + + @if (pokemon.IsVariation) + { + @if (pokemon.VariationName == "Alolan") + { + Alolan @pokemon.PokemonName + } + @if (pokemon.VariationName == "Paldean") + { + Paldean @pokemon.PokemonName + } + } + else // Base Case + { + @pokemon.PokemonName + } + + + @pokemon.SleepType + @pokemon.Speciality + + + + + + + + + + + } + + +
+
-
} @code { private List pokemons = new List(); + private bool showForm = true; + + protected override async Task OnInitializedAsync() { - // Simulate asynchronous loading to demonstrate streaming rendering - await Task.Delay(500); var result = await PokemonService.GetAllPokemonAsync(); if (result is not null) @@ -87,4 +140,6 @@ else pokemons = result; } } + + } diff --git a/Portfolio.WebUI.Server/wwwroot/pokemon_images/normal/980.png b/Portfolio.WebUI.Server/wwwroot/pokemon_images/normal/980-paldeanclodsire.png similarity index 100% rename from Portfolio.WebUI.Server/wwwroot/pokemon_images/normal/980.png rename to Portfolio.WebUI.Server/wwwroot/pokemon_images/normal/980-paldeanclodsire.png diff --git a/Portfolio.WebUI.Server/wwwroot/pokemon_images/shiny/980.png b/Portfolio.WebUI.Server/wwwroot/pokemon_images/shiny/980-paldeanclodsire.png similarity index 100% rename from Portfolio.WebUI.Server/wwwroot/pokemon_images/shiny/980.png rename to Portfolio.WebUI.Server/wwwroot/pokemon_images/shiny/980-paldeanclodsire.png