public async Task <Customer> AddCustomer(Customer customer, string userId) { if (await _customerRepository.GetCustomerByNameAsync(customer.Name) != null) { _customExceptionService.ThrowInvalidOperationException("Name already exists"); return(null); } _customerRepository.AddCustomer(customer); //Add registry operation if (await _customerRepository.SaveChangesAsync()) { CustomerAudit customerAudit = new CustomerAudit { Date = DateTime.Now, Operation = CustomerAuditOperationType.Create, Customer = customer }; _customerRepository.AddCustomerAudit(customerAudit, userId); if (await _customerRepository.SaveChangesAsync()) { return(customer); } } else { _customExceptionService.ThrowInvalidOperationException("Error adding customer"); } return(null); }