示例#1
0
        /// <summary>
        /// Loads the attribute controls.
        /// </summary>
        /// <param name="marketingCampaignAd">The marketing campaign ad.</param>
        /// <param name="createControls">if set to <c>true</c> [create controls].</param>
        /// <param name="setValues">if set to <c>true</c> [set values].</param>
        private void LoadAdAttributes(Rock.Attribute.IHasAttributes marketingCampaignAd, bool createControls, bool setValues)
        {
            if (string.IsNullOrWhiteSpace(ddlMarketingCampaignAdType.SelectedValue))
            {
                return;
            }

            int marketingAdTypeId = int.Parse(ddlMarketingCampaignAdType.SelectedValue);

            MarketingCampaignAdType adType = MarketingCampaignAdType.Read(marketingAdTypeId);

            tbAdDateRangeEndDate.Visible = adType.DateRangeType.Equals(DateRangeTypeEnum.DateRange);

            List <Rock.Model.Attribute> attributesForAdType = GetAttributesForAdType(marketingAdTypeId);

            marketingCampaignAd.Attributes          = marketingCampaignAd.Attributes ?? new Dictionary <string, Rock.Web.Cache.AttributeCache>();
            marketingCampaignAd.AttributeCategories = marketingCampaignAd.AttributeCategories ?? new SortedDictionary <string, List <string> >();
            marketingCampaignAd.AttributeValues     = marketingCampaignAd.AttributeValues ?? new Dictionary <string, List <AttributeValueDto> >();
            foreach (var attribute in attributesForAdType)
            {
                marketingCampaignAd.Attributes[attribute.Key] = Rock.Web.Cache.AttributeCache.Read(attribute);
                if (marketingCampaignAd.AttributeValues.Count(v => v.Key.Equals(attribute.Key)) == 0)
                {
                    List <AttributeValueDto> attributeValues = new List <AttributeValueDto>();
                    attributeValues.Add(new AttributeValueDto {
                        Value = attribute.DefaultValue
                    });
                    marketingCampaignAd.AttributeValues.Add(attribute.Key, attributeValues);
                }
            }

            foreach (var category in attributesForAdType.Select(a => a.Category).Distinct())
            {
                marketingCampaignAd.AttributeCategories[category] = attributesForAdType.Where(a => a.Category.Equals(category)).Select(a => a.Key).ToList();
            }

            if (createControls)
            {
                phAttributes.Controls.Clear();
                Rock.Attribute.Helper.AddEditControls(marketingCampaignAd, phAttributes, setValues);
            }
        }