public async Task <IActionResult> Post(CustomerDto customerDto) { try { if (customerDto == null) { _logger.LogError("Customer object sent from client is null."); return(BadRequest("Customer object is null")); } if (!ModelState.IsValid) { _logger.LogError("Invalid Customer object sent from client."); return(BadRequest("Invalid model object")); } bool customerExists = _repo.DoesCustomerAlreadyExists(customerDto); if (!customerExists) { var result = await _repo.AddCustomer(customerDto); _logger.LogInformation($"customer Added with First Name : {customerDto.FirstName} and Last Name : {customerDto.LastName}"); return(CreatedAtRoute("GetCustomerById", new { id = result.Id }, customerDto)); } else { _logger.LogError($"customer already exists with the given First Name : {customerDto.FirstName} and Last Name : {customerDto.LastName}"); } return(StatusCode(200, $"customer already exists with the given First Name : {customerDto.FirstName} and Last Name : {customerDto.LastName}")); } catch (Exception ex) { _logger.LogError($"Something went wrong inside Add Customer action: {ex.Message}"); return(StatusCode(500, "Internal server error :" + ex.Message)); } }