public async Task <ClienteForCreationDto> Create(ClienteForCreationDto clienteForCreationDto) { using (SqlConnection con = new SqlConnection(CadenaConexion)) { await con.OpenAsync(); var clienteEntity = _mapper.Map <Cliente>(clienteForCreationDto); var clienteIdReturn = await _clienteRepository.Create(clienteEntity, con); clienteForCreationDto.codigoCliente = clienteIdReturn; } return(clienteForCreationDto); }
public async Task <IActionResult> CreateCliente([FromBody] ClienteForCreationDto clienteForCreationDto) { if (clienteForCreationDto == null) { _logger.LogError("El objeto clienteForCreationDto enviado desde el cliente es nulo."); return(BadRequest("No puede enviar un cliente nulo.")); } if (!ModelState.IsValid) { _logger.LogError("Estado de modelo no válido para el objeto EmployeeForCreationDto"); return(UnprocessableEntity(ModelState)); } var result = await _clienteService.Create(clienteForCreationDto); return(CreatedAtRoute("clienteCreate", new { id = result.codigoCliente }, result)); }