Exemplo n.º 1
0
        public async Task <IActionResult> CreatePositionAsync([FromBody] ZooAnimalRegisterDto obj)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(new ResponseErrorDto((int)HttpStatusCode.BadRequest, "Review Required Parameters")));
                }
                var created = await _animalService.CreateAnimalAsync(obj, User.GetIdUser());

                return(CreatedAtAction(nameof(GetAnimalByIdAsync).Replace("Async", string.Empty), new { id = created }, new ResponseDto <ZooAnimalRegisterDto>((int)HttpStatusCode.Created, "Ok", obj)));
            }
            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 create the animal information.", guid)));
            }
        }