diff --git a/Portfolio.Application/Services/PokemonService/IPokemonService.cs b/Portfolio.Application/Services/PokemonService/IPokemonService.cs index a53b3e2..bd59cc2 100644 --- a/Portfolio.Application/Services/PokemonService/IPokemonService.cs +++ b/Portfolio.Application/Services/PokemonService/IPokemonService.cs @@ -11,5 +11,6 @@ namespace Portfolio.Application.Services.PokemonService { Task> GetAllPokemonAsync(); Task AddPokemonAsync(Pokemon pokemon); + Task DeletePokemonAsync(int pokemonId); } } diff --git a/Portfolio.Application/Services/PokemonService/PokemonService.cs b/Portfolio.Application/Services/PokemonService/PokemonService.cs index 6f9e8e9..00443e7 100644 --- a/Portfolio.Application/Services/PokemonService/PokemonService.cs +++ b/Portfolio.Application/Services/PokemonService/PokemonService.cs @@ -22,6 +22,10 @@ namespace Portfolio.Application.Services.PokemonService { await _pokemonRepository.AddPokemonAsync(pokemon); } + public async Task DeletePokemonAsync(int pokemonId) + { + await _pokemonRepository.DeletePokemonAsync(pokemonId); + } public async Task> GetAllPokemonAsync() { diff --git a/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs b/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs index bea253d..0539bc4 100644 --- a/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs +++ b/Portfolio.Domain/Features/Pokemon/IPokemonRepository.cs @@ -10,5 +10,7 @@ namespace Portfolio.Domain.Features.Pokemon { Task> GetAllPokemonsAsync(); Task AddPokemonAsync(Pokemon pokemon); + Task DeletePokemonAsync(int pokemonId); + } } diff --git a/Portfolio.Infrastructure/Repositories/PokemonRepository.cs b/Portfolio.Infrastructure/Repositories/PokemonRepository.cs index 52149de..3d34313 100644 --- a/Portfolio.Infrastructure/Repositories/PokemonRepository.cs +++ b/Portfolio.Infrastructure/Repositories/PokemonRepository.cs @@ -26,5 +26,14 @@ namespace Portfolio.Infrastructure.Repositories _context.Pokemons.Add(pokemon); await _context.SaveChangesAsync(); } + public async Task DeletePokemonAsync(int pokemonId) + { + var pokemon = await _context.Pokemons.FindAsync(pokemonId); + if (pokemon != null) + { + _context.Pokemons.Remove(pokemon); + await _context.SaveChangesAsync(); + } + } } } diff --git a/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor b/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor index 00b4c9a..0d0dce4 100644 --- a/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor +++ b/Portfolio.WebUI.Server/Components/Pages/PokemonSleep.razor @@ -1,6 +1,7 @@ @page "/pokemonsleep" @inject IPokemonService PokemonService +@inject IJSRuntime JS @attribute [StreamRendering] @rendermode InteractiveServer @@ -121,9 +122,13 @@ else string BaseURL = $"/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 @@ -131,8 +136,8 @@ else string BaseURL = $"/pokemon_images/normal/{pokemon.PokemonId}.png"; ; string ShinyURL = $"/pokemon_images/shiny/{pokemon.PokemonId}.png"; -
-
+
+
@@ -167,14 +172,15 @@ else @pokemon.Speciality - - - - - - + + + + @@ -203,18 +209,34 @@ else // Initialize dictionary with false (show base image first) foreach (var pokemon in pokemons) { - isShiny[pokemon.PokemonId] = false; + isShiny[pokemon.Id] = false; } } } - private void ToggleImage(int pokemonId) + private void ToggleImage(int Id) { - if (isShiny.ContainsKey(pokemonId)) + if (isShiny.ContainsKey(Id)) { - isShiny[pokemonId] = !isShiny[pokemonId]; + isShiny[Id] = !isShiny[Id]; + } + } + private async Task ConfirmDelete(int Id) + { + bool confirm = await JS.InvokeAsync("confirm", "Are you sure you want to delete this Pokémon?"); + if (confirm) + { + await DeletePokemon(Id); } } + private async Task DeletePokemon(int Id) + { + await PokemonService.DeletePokemonAsync(Id); + pokemons.RemoveAll(p => p.Id == Id); // Remove from the list locally + StateHasChanged(); // Refresh the UI + } + + }