예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
        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"));
            }
        }
예제 #5
0
 public void DeletePokemon(int id)
 {
     _repository.DeletePokemon(id);
 }