public Guid GetOrCreateConsumerId(string consumerId, Countries country, string emailHash) { var countryDto = _countryManager.GetCountryByCode(country); if (IsAlreadyExistingConsumerId(country, emailHash, out var consumerCrmId)) { return(consumerCrmId); } var consumer = new Consumer { CountryId = countryDto.Id, ConsumerId = consumerId, EmailHash = emailHash }; return(Create(consumer)); }
public async Task <(bool success, string consumerId)> UpdateUserInformationAsync(UserInfoDto userInfo) { var consumerId = string.Empty; var participationDto = _participationManager.FindById(userInfo.ParticipationId); if (participationDto.JourneyStatus != JourneyStatus.WON_CHECKED.ToString()) { return(false, consumerId); } participationDto.CountryId = _countryManager.GetCountryByCode(userInfo.Country)?.Id; participationDto.JourneyStatus = userInfo.PaymentType == PaymentType.BACS_TRANSFER ? JourneyStatus.BACS_TRANSFERT_NOT_SYNC.ToString() : JourneyStatus.CHEQUE_PAYMENT_NOT_SYNC.ToString(); await Task.Run(() => _participationManager.UpdateParticipation(participationDto)); var prize = _prizeManager.FindById(participationDto.PrizeId.Value); if (prize == null) { return(false, consumerId); } var data = new CrmDto(); data.Firstname = userInfo.Firstname; data.Lastname = userInfo.Lastname; data.Email = userInfo.Email; data.PhoneNumber = userInfo.MobilePrivate; data.Address = userInfo.Street1; data.AdditionalAddress = userInfo.Street2; data.City = userInfo.City; data.ZipCode = userInfo.Zipcode; data.Country = userInfo.Country; data.AccountNumber = userInfo.AccountNumber; data.SortCode = userInfo.SortCode; data.PaymentType = userInfo.PaymentType; data.PrizeValue = prize.Value; data.ParticipationId = participationDto.Id; data.IBAN = userInfo.IBAN; data.BIC = userInfo.BIC; var response = await _crmService.SendDataToSynchronizeAsync(data); if (response.Success) { consumerId = response.ConsumerId; // Update Successful sync Status participationDto.JourneyStatus = userInfo.PaymentType == PaymentType.BACS_TRANSFER ? JourneyStatus.BACS_PARTICIPATION_SYNCED.ToString() : JourneyStatus.CHEQUE_PARTICIPATION_SYNCED.ToString(); await Task.Run(() => _participationManager.UpdateParticipation(participationDto)); // Save ConsumerId var participantDto = _participantManager.FindById(participationDto.ParticipantId); participantDto.ConsumerId = consumerId; await Task.Run(() => _participantManager.UpdateParticipant(participantDto)); } return(response.Success, consumerId); }