示例#1
0
        /// <summary>
        /// update cancellation information for an opted in channel
        /// </summary>
        /// <param name="channelTerms">channel cancel terms to use</param>
        /// <param name="channelUpdateInfo">data to change</param>
        public bool UpdateCancellationForOptedInChannel(BusinessChannelOptIn channelUpdateInfo, ChannelCancellationTerms channelTerms = null)
        {
            var result = false;

            if (channelUpdateInfo.IsValid() &&
                channelUpdateInfo.CancellationValues != null)
            {
                // verify they can edit cancellation details
                Channel currentChannel = channelDao.GetById(channelUpdateInfo.ChannelId.Value);

                if (currentChannel == null)
                {
                    //throw error if we cannot find the channel
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30130,
                                                                                 "DistributionManager.UpdateCancellationForOptedInChannel",
                                                                                 additionalDescriptionParameters:
                                                                                     new object[]
                                                                                         {
                                                                                             channelUpdateInfo.ChannelId
                                                                                                              .Value
                                                                                         },
                                                                                 arguments:
                                                                                     new object[] { channelUpdateInfo }));
                }

                if (currentChannel.SupportsCustomCancPolicy == false)
                {
                    //throw error if we don't support custom cancel
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30131,
                                                                                 "DistributionManager.UpdateCancellationForOptedInChannel",
                                                                                 additionalDescriptionParameters:
                                                                                     new object[] { currentChannel.ShortName },
                                                                                 arguments:
                                                                                     new object[] { currentChannel.ShortName }));
                }

                // get restrictions for editing here
                List<ChannelCancellationTerms> ListOfChannelTerms = null;
                if (channelTerms == null)
                {
                    ListOfChannelTerms = channelCancellationTermsDao.GetByBusiness(channelUpdateInfo.BusinessId.Value);
                    channelTerms = ListOfChannelTerms.FirstOrDefault(ct => ct.ChannelId == currentChannel.Id);
                }
                //channel terms would be null if the business is not subscribed to the channel
                if (channelTerms != null)
                {
                    // set the terms to the channels
                    currentChannel.ChannelCancellationTerms = channelTerms;


                    if (channelUpdateInfo.IsCustomCancelValid(currentChannel.ChannelCancellationTerms) == false)
                    {
                        throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30132,
                                                                                     "DistributionManager.UpdateCancellationForOptedInChannel",
                                                                                     additionalDescriptionParameters:
                                                                                         new object[] { currentChannel.ShortName },
                                                                                     arguments:
                                                                                         new object[] { currentChannel.ShortName }));
                    }
                }
               

                using (var tx = new BusinessTransaction())
                {
                    result = businessChannelOptInDao.UpdateCancellation(channelUpdateInfo);

                    // Record business event
                    eventTrackingManager.CreateBusinessEventAsync(channelUpdateInfo.BusinessId.Value,
                                                             BusinessEventTypesEnum.OptinChannelModified,
                                                             channelUpdateInfo.ChannelId.ToString());

                    tx.Commit();
                }

                // if not a channel (so a group) update the related channels
                if (currentChannel.ChannelType != ChannelTypeEnum.Channel)
                {
                    // update the opted in related channels with this info as well
                    List<int> channelIds = businessChannelOptInDao.GetOptedInChannelsRelatedToGroup(channelUpdateInfo.BusinessId.Value, currentChannel.Id);

                    if (channelIds != null &&
                        channelIds.Any())
                    {
                        foreach (int channelId in channelIds)
                        {
                            channelUpdateInfo.ChannelId = channelId;
                            UpdateCancellationForOptedInChannel(channelUpdateInfo, channelTerms); // update the sub-channel
                        }
                    }
                }
            }

            return result;
        }
示例#2
0
        /// <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);
                }
            }
示例#3
0
        /// <summary>
        /// Modify Channel PrePay Settings
        /// </summary>
        /// <param name="channelOptIn">Channel Opt In Record</param>
        /// <param name="permittedSettings">settings permitted</param>
        /// <returns>True if created</returns>
        public bool UpdatePrePayForOptedInChannel(BusinessChannelOptIn channelOptIn, List<ChannelPrePayPermittedSetting> permittedSettings = null)
        {
            var success = false;

            if (channelOptIn.IsValid() && channelOptIn.PrePaySettings != null)
            {
                // verify they can edit prepay details
                var currentChannel = channelDao.GetById(channelOptIn.ChannelId.Value);

                if (currentChannel == null)
                {
                    //throw error if we cannot find the channel
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30130,
                                                                                 "DistributionManager.UpdatePrePayForOptedInChannel",
                                                                                 additionalDescriptionParameters:
                                                                                     new object[] { channelOptIn.ChannelId.Value },
                                                                                 arguments: new object[] { channelOptIn }));
                }

                // retrieve settings if null (will be not null when validating for a group channel as will be supplied below)
                if (permittedSettings == null)
                {
                    permittedSettings = prePayDao.GetPermittedChannelSettings(channelOptIn.BusinessId.Value, channelOptIn.ChannelId.Value);
                }

                var suppliedSetting = channelOptIn.PrePaySettings;
                if (suppliedSetting.Type != PrePayRuleTypeEnum.Unknown)
                {
                var permittedSetting = permittedSettings.First(c => c.Type == suppliedSetting.Type);

                // if supplied values are not valid then throw exception
                if (suppliedSetting.Value < permittedSetting.Min || suppliedSetting.Value > permittedSetting.Max)
                {
                    throw new ValidationException(ErrorFactory.CreateAndLogError(Errors.SRVEX30135,
                                                                                 "DistributionManager.UpdatePrePayForOptedInChannel",
                                                                                 additionalDescriptionParameters:
                                                                                     new object[] { currentChannel.ShortName },
                                                                                 arguments:
                                                                                     new object[] { currentChannel.ShortName }));
                }

                using (var tx = new BusinessTransaction())
                {
                    success = businessChannelOptInDao.UpdatePrePaySettings(channelOptIn);

                    tx.Commit();
                }

                // Record business event
                eventTrackingManager.CreateBusinessEventAsync(channelOptIn.BusinessId.Value, BusinessEventTypesEnum.OptinChannelModified, channelOptIn.ChannelId.Value.ToString(CultureInfo.InvariantCulture), string.Format("{0} - {1}", suppliedSetting.Type, suppliedSetting.Value));


                // if not a channel (so a group) update the related channels
                if (currentChannel.ChannelType != ChannelTypeEnum.Channel)
                {
                    // update the opted in related channels with this info as well
                    var channelIds = businessChannelOptInDao.GetOptedInChannelsRelatedToGroup(channelOptIn.BusinessId.Value, currentChannel.Id);

                    if (channelIds != null && channelIds.Any())
                    {
                        foreach (var channelId in channelIds)
                        {
                            channelOptIn.ChannelId = channelId;
                            UpdatePrePayForOptedInChannel(channelOptIn, permittedSettings); // update the sub-channel validating against permitted settings for the group channel
                        }
                    }
                    }                    
                }
            }

            return success;
        }