private CrmData GatherParticipationDataToSync(CrmDto data, CrmData legalDocument) { var crmData = new CrmData(); crmData.Data.Firstname = data.Firstname; crmData.Data.Lastname = data.Lastname; crmData.Data.Email = data.Email; crmData.Data.MobilePrivate = data.PhoneNumber; crmData.Data.Street1 = data.Address; crmData.Data.Street2 = data.AdditionalAddress; crmData.Data.City = data.City; crmData.Data.ZipCode = data.ZipCode; crmData.Data.Country = data.Country; crmData.Data.AccountNumber = data.AccountNumber; crmData.Data.SortCode = data.SortCode; crmData.Data.IBAN = data.IBAN; crmData.Data.BIC = data.BIC; crmData.Data.PrivacyPolicyTextName = legalDocument.Data.Data.Versions[0].LegalTextName; crmData.Data.PrivacyPolicyVersion = legalDocument.Data.Data.Versions[0].Version; crmData.Data.PrivacyPolicyCreation = legalDocument.Data.Data.Versions[0].Created.ToString(); crmData.Data.Payment = data.PaymentType; crmData.Data.PrizeValue = data.PrizeValue; crmData.Data.ParticipationId = data.ParticipationId; return(crmData); }
public async Task <CrmResponse> SendDataToSynchronizeAsync(CrmDto data) { _crmProvider.Configuration.AddSetting("ApiKey", ConfigurationManager.AppSettings[$"CSX:Consumer:ApiKey:{data.Country.ToString()}"]); _crmProvider.Configuration.AddSetting("ApiSecret", ConfigurationManager.AppSettings[$"CSX:Consumer:ApiSecret:{data.Country.ToString()}"]); var legalDocument = await _crmProvider.ReadTextDocumentAsync(); var crmData = GatherParticipationDataToSync(data, legalDocument); var consumer = await _crmProvider.CreateParticipationAsync(crmData, _crmProvider.Configuration, true); return(new CrmResponse { Success = consumer.GetSetting <bool>("Success"), ConsumerId = consumer.GetSetting <bool>("Success") ? (string)consumer.Data.Data.ConsumerId : string.Empty, ApiStatus = consumer.GetSetting <int>("ApiStatus").ToString(), ApiMessage = consumer.GetSetting <string>("ApiMessage") }); }
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); }