public async Task <ServiceResponse <GetPokemonDto> > Handle(PokemonDeleteCommand request, CancellationToken cancellationToken) { ServiceResponse <GetPokemonDto> serviceResponse = new ServiceResponse <GetPokemonDto>(); try { var pokemonDto = await _pokemonRepository.GetPokemon(EnumPokemonSelectOptions.Number, request.Number.ToString()); if (String.IsNullOrEmpty(pokemonDto.Name)) { throw new ArgumentException(); } await _pokemonRepository.DeletePokemon(request.Number); serviceResponse.Message = $"Pokemon: {pokemonDto.Name}, has been removed."; } catch (Exception e) { serviceResponse.Success = false; serviceResponse.Message = "Sorry, we can't find any info about that pokemon."; } return(serviceResponse); }
public async Task DeletePokemon_ByEntryAndGen(int pokedexEntry, int generation) { // Remove Pokemon by entry and gen // Search for a Pokemon by entry and gen (unique values) //Pokemon pokemon = await _pokemonRepository.GetPokemon_ByEntryAndGen(pokedexEntry, generation, DetailLevel.ForeignKeys); Pokemon pokemon = await _pokemonRepository.GetPokemon_ByEntryAndGen(pokedexEntry, generation); if (pokemon == null) { return; } // Remove Pokemon await _pokemonRepository.DeletePokemon(pokemon); }
public void DeletePokemon(string name) { if (name == null) { throw new BadRequestException($"Pokemon require a name."); } if (!_repository.PokemonExist(name)) { throw new NotFoundException($"Pokemon with name {name} not found."); } try { _repository.DeletePokemon(_repository.GetPokemonByName(name)); } catch (Exception ex) { throw new BusinessException(ex.Message); } }
public async Task <ActionResult <Pokemon> > DeletePokemon(int id) { try { var pokemonToDelete = await _pokemonRepository.GetPokemon(id); if (pokemonToDelete == null) { return(NotFound($"Pokemon with Id = {id} not found")); } return(await _pokemonRepository.DeletePokemon(id)); } catch (Exception) { return(StatusCode(StatusCodes.Status500InternalServerError, "Error deleting data")); } }
public void DeletePokemon(int id) { _repository.DeletePokemon(id); }