示例#1
0
        public bool DeletePokemon(DeletePokemonDto dto)
        {
            if (dto.PokemonId == 0 || dto.UserId == 0)
            {
                return(false);
            }

            var user = _unitOfWork.UserRepository.Entities.FirstOrDefault(x => x.Id == dto.UserId);

            if (user is null)
            {
                return(false);
            }

            var userPokemon = _unitOfWork.UserPokemonRepository.Entities.FirstOrDefault(x => x.PokemonId == dto.PokemonId);

            try
            {
                _unitOfWork.UserPokemonRepository.Remove(userPokemon);

                if (userPokemon != null && user.MainPokemonId == userPokemon.PokemonId)
                {
                    user.MainPokemonId = 0;
                    _unitOfWork.Commit();
                }
            }
            catch
            {
                return(false);
            }

            return(true);
        }
示例#2
0
        public IActionResult DeletePokemon([FromBody] DeletePokemonDto dto)
        {
            bool result = _gameService.DeletePokemon(dto);

            if (!result)
            {
                return(BadRequest());
            }
            return(Ok());
        }