Пример #1
0
        public async Task <IActionResult> Put(Guid id, [FromBody] RequestPizza pizza)
        {
            try
            {
                pizza.Id = id;

                if (await _servicePizza.Update(_mapper.Map <Pizza>(pizza)))
                {
                    return(NoContent());
                }

                return(BadRequest(new FailResponse($"Erro alterar o cadastro.")));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new FailResponse(e.Message, e)));
            }
        }
Пример #2
0
        public async Task <IActionResult> Post([FromBody] RequestPizza pizza)
        {
            try
            {
                pizza.Id = Guid.NewGuid();

                if (await _servicePizza.Add(_mapper.Map <Pizza>(pizza)))
                {
                    return(Ok(new ResponseAdded()
                    {
                        Id = pizza.Id
                    }));
                }

                return(BadRequest(new FailResponse($"Erro ao cadastrar.")));
            }
            catch (Exception e)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, new FailResponse(e.Message, e)));
            }
        }