예제 #1
0
        public IActionResult CreateCliente([FromBody] AddClienteRequest cliente)
        {
            if (cliente == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResult(ModelState));
            }

            var clienteEntity = Mapper.Map <Cliente>(cliente);

            _clientesRepository.AddCliente(clienteEntity);

            if (!_clientesRepository.Save())
            {
                throw new Exception("Fallo al guardar cliente");
            }

            var clienteToReturn = Mapper.Map <ClienteResponse>(clienteEntity);

            return(CreatedAtRoute("GetCliente",
                                  new { id = clienteToReturn.Id },
                                  clienteToReturn));
        }
        public async Task <ActionResult <Clientes> > PostClientes(Clientes clientes)
        {
            clientesRepository.AddCliente(clientes);
            var verificaSave = await Task.FromResult(clientesRepository.Save());

            if (verificaSave)
            {
                return(CreatedAtAction("GetClientes", new { id = clientes.Id }, clientes));
            }
            else
            {
                return(NoContent());
            }
        }