/// <summary> /// Opt in to a channel /// </summary> /// <param name="businessChannelOptIn">The businessChannelOptIn object to create</param> /// <param name="cultureCode">The culture code used for translations</param> public void OptInToChannel(BusinessChannelOptIn businessChannelOptIn, string cultureCode ) { var prePaySettings = new BusinessChannelPrePaySettings(); Channel logicalGroup = null; using (var tx = new BusinessTransaction()) { if (businessChannelOptIn.IsValid()) { businessChannelOptIn.ChannelOptInStatus = new ChannelOptInStatus { Code = ChannelOptInStatusEnum.Live.GetCode() }; businessChannelOptIn.OptInDatetime = DateTime.UtcNow; businessChannelOptInDao.Create(businessChannelOptIn); // Record business event eventTrackingManager.CreateBusinessEventAsync(businessChannelOptIn.BusinessId.Value, BusinessEventTypesEnum.ChannelOptIn, businessChannelOptIn.ChannelId.ToString()); logicalGroup = channelDao.GetFirstLogicalGroupChannelByChannelId(businessChannelOptIn.ChannelId.Value); if (logicalGroup == null) { var channel = channelDao.GetById(businessChannelOptIn.ChannelId.Value); var business = businessDao.GetByKey(businessChannelOptIn.BusinessId.Value); var permittedSettings = prePayDao.GetPermittedChannelSettings(businessChannelOptIn.BusinessId.Value, businessChannelOptIn.ChannelId.Value); channel.FullPrePaySettings = new ChannelPrePaySettings { PermittedSettings = permittedSettings }; // if the channel isnt flexible use the channel defaults otherwise use the business defaults if (!channel.FullPrePaySettings.Flexible) { if (channel.DefaultPrePayType.HasValue && channel.DefaultPrePayValue.HasValue) { prePaySettings.Type = channel.DefaultPrePayType.Value; prePaySettings.Value = channel.DefaultPrePayValue.Value; prePaySettings.IsOverridden = false; } } else { if (business.PrePayRuleValue.HasValue) { prePaySettings.Type = business.PrePayRuleType; prePaySettings.Value = business.PrePayRuleValue.Value; prePaySettings.IsOverridden = false; } } businessChannelOptIn.PrePaySettings = prePaySettings; // Update pre pay settings on Opt In UpdatePrePayForOptedInChannel(businessChannelOptIn, permittedSettings); } tx.Commit(); } } // update logical group channel to opt into if needed if (businessChannelOptIn.IsValid() && logicalGroup != null) { // if not already opted in, opt the logical group channel in if (businessChannelOptInDao.IsChannelOptedInForBusiness(businessChannelOptIn.BusinessId.Value, logicalGroup.Id) == false) { BusinessChannelOptIn bco = new BusinessChannelOptIn { BusinessId = businessChannelOptIn.BusinessId.Value, ChannelId = logicalGroup.Id, ChannelTermsId = logicalGroup.ChannelTermsId ?? businessChannelOptIn.ChannelTermsId.Value, PrePaySettings = prePaySettings }; OptInToChannel(bco, cultureCode); } // in all cases, update this channel with info from logical group // need to update cancel / ppy info here based on logical group settings UpdateGroupChannelsWithCancelPrepaySettings(logicalGroup, businessChannelOptIn, cultureCode); } }
public PrePaySettings() { PermittedSettings = new List<ChannelPrePaySetting>(); Setting = new BusinessChannelPrePaySettings(); }