public async Task <CustomerProfileErrorCodes> SetPhoneAsVerifiedAsync(string customerId) { var customerProfile = await _customerProfileRepository.GetByCustomerIdAsync(customerId, includeNotVerified : true); if (customerProfile == null) { return(CustomerProfileErrorCodes.CustomerProfileDoesNotExist); } if (string.IsNullOrEmpty(customerProfile.PhoneNumber)) { return(CustomerProfileErrorCodes.CustomerProfilePhoneIsMissing); } var isPhoneNumberUsedByAnotherCustomer = await _customerProfileRepository.IsPhoneNumberUsedByAnotherCustomer(customerId, customerProfile.PhoneNumber); if (isPhoneNumberUsedByAnotherCustomer) { return(CustomerProfileErrorCodes.PhoneAlreadyExists); } var(error, wasPhoneEverVerified) = await _customerProfileRepository.SetPhoneAsVerifiedAsync(customerId); switch (error) { case CustomerProfileErrorCodes.CustomerProfileDoesNotExist: _log.Warning("Customer Profile does not exists", context: customerId); break; case CustomerProfileErrorCodes.CustomerProfilePhoneAlreadyVerified: _log.Warning("Customer profile phone is already verified", context: customerId); break; case CustomerProfileErrorCodes.None: _log.Info("Customer profile phone is successfully verified", context: customerId); await _phoneVerifiedPublisher.PublishAsync(new CustomerPhoneVerifiedEvent { CustomerId = customerId, WasPhoneEverVerified = wasPhoneEverVerified, Timestamp = DateTime.UtcNow }); break; default: throw new ArgumentOutOfRangeException(); } return(error); }