public async Task <CustomerProfileErrorCodes> CreateIfNotExistsAsync(ICustomerProfile customerProfile) { var isSocialAccountProfile = customerProfile.LoginProviders.Any(p => p != LoginProvider.Standard); if (isSocialAccountProfile) { customerProfile.IsEmailVerified = true; } if (customerProfile.CountryOfNationalityId.HasValue) { var countryResult = await _dictionariesClient.Salesforce.GetCountryOfResidenceByIdAsync( customerProfile.CountryOfNationalityId.Value); if (countryResult == null) { return(CustomerProfileErrorCodes.InvalidCountryOfNationalityId); } } var creationResult = await _customerProfileRepository.CreateIfNotExistAsync(customerProfile); switch (creationResult) { case CustomerProfileErrorCodes.CustomerProfileAlreadyExistsWithDifferentProvider: _log.Warning("Customer Profile already exists but with different login provider", context: customerProfile.CustomerId); return(creationResult); case CustomerProfileErrorCodes.CustomerProfileAlreadyExists: _log.Warning("Customer Profile already exists", context: customerProfile.CustomerId); return(creationResult); } _log.Info("Customer profile is created", context: customerProfile.CustomerId); if (isSocialAccountProfile) { Task.Run(async() => { try { await _emailVerifiedPublisher.PublishAsync(new EmailVerifiedEvent { CustomerId = customerProfile.CustomerId, TimeStamp = DateTime.UtcNow }); } catch (Exception e) { _log.Error(e); } }); } return(creationResult); }