public async Task <ActionResult <ClienteResource> > updateCliente(int id, [FromBody] SaveClienteResource saveClienteResource) { var validator = new SaveClienteResourceValidator(); var validationResult = await validator.ValidateAsync(saveClienteResource); var requestIsInvalid = id == 0 || !validationResult.IsValid; if (requestIsInvalid) { return(BadRequest(validationResult.Errors)); } var clienteToBeUpdate = await _clienteService.getClienteId(id); if (clienteToBeUpdate == null) { return(NotFound()); } var cliente = _mapper.Map <SaveClienteResource, Cliente>(saveClienteResource); await _clienteService.updateCliente(clienteToBeUpdate, cliente); var updatedCliente = await _clienteService.getClienteId(id); var updatedClienteResource = _mapper.Map <Cliente, ClienteResource>(updatedCliente); return(Ok(updatedClienteResource)); }
public async Task <ActionResult <ClienteResource> > createCliente([FromBody] SaveClienteResource saveClienteResource) { var validator = new SaveClienteResourceValidator(); var validationResult = await validator.ValidateAsync(saveClienteResource); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } var clienteToCreate = _mapper.Map <SaveClienteResource, Cliente>(saveClienteResource); var newCliente = await _clienteService.createCliente(clienteToCreate); var cliente = await _clienteService.getClienteId(newCliente.Id); var clienteResource = _mapper.Map <Cliente, ClienteResource>(cliente); return(Ok(clienteResource)); }