public async Task <ActionResult> Create(CustomerCreateViewModel model) { try { var CustomerDto = new CustomerCreateDTO { PhoneNumber = model.PhoneNumber, FullName = model.FullName, Email = model.Email, Gender = model.Gender, Address = model.Address }; await _customerService.Create(CustomerDto).ConfigureAwait(true); var Customer = await _customerRepo.GetByNumber(CustomerDto.PhoneNumber) ?? throw new CustomerNotFoundException(); return(Ok(CreateReponseDto(Customer))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
private async Task ValidateCustomerNumber(string phoneNumber, Customer?customer = null) { var CustomerByNumber = await _customerRepo.GetByNumber(phoneNumber).ConfigureAwait(false); if (CustomerByNumber != null && CustomerByNumber != customer) { throw new Exception("Customer Number already registered."); } return; }