Exemplo n.º 1
0
        public async Task <IActionResult> GetAnimalByIdAsync([FromRoute][Required] int id)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(new ResponseErrorDto((int)HttpStatusCode.BadRequest, "Review Required Parameters")));
                }
                var animal = await _animalService.GetAnimalByIdAsync(id);

                if (animal == null)
                {
                    return(NoContent());
                }
                return(Ok(new ResponseDto <ZooAnimalDto>((int)HttpStatusCode.OK, "Ok", animal)));
            }
            catch (ExceptionDto exdto)
            {
                return(StatusCode((int)HttpStatusCode.InternalServerError, new ResponseErrorDto((int)HttpStatusCode.InternalServerError, exdto.UserMessage, exdto.Id)));
            }
            catch (Exception ex)
            {
                var guid = Guid.NewGuid();
                _logger.Log(LogLevel.Error, ex, guid.ToString());
                return(BadRequest(new ResponseErrorDto((int)HttpStatusCode.BadRequest, "Failed to find animal information.", guid)));
            }
        }