Exemplo n.º 1
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            var            rockContext = new RockContext();
            ContentChannel contentChannel;

            ContentChannelService contentChannelService = new ContentChannelService(rockContext);
            CategoryService       categoryService       = new CategoryService(rockContext);

            int contentChannelId = hfId.Value.AsInteger();

            if (contentChannelId == 0)
            {
                contentChannel = new ContentChannel {
                    Id = 0
                };
                contentChannelService.Add(contentChannel);
            }
            else
            {
                contentChannel = contentChannelService.Get(contentChannelId);
            }

            if (contentChannel != null)
            {
                contentChannel.Name                         = tbName.Text;
                contentChannel.Description                  = tbDescription.Text;
                contentChannel.ContentChannelTypeId         = ddlChannelType.SelectedValueAsInt() ?? 0;
                contentChannel.IsStructuredContent          = cbIsStructuredContent.Checked;
                contentChannel.StructuredContentToolValueId = dvEditorTool.SelectedDefinedValueId;
                contentChannel.ContentControlType           = ddlContentControlType.SelectedValueAsEnum <ContentControlType>();
                contentChannel.RootImageDirectory           = tbRootImageDirectory.Visible ? tbRootImageDirectory.Text : string.Empty;
                contentChannel.IconCssClass                 = tbIconCssClass.Text;

                // the cbRequireApproval will be hidden if contentChannelType.DisableStatus == True
                contentChannel.RequiresApproval          = cbRequireApproval.Visible && cbRequireApproval.Checked;
                contentChannel.IsIndexEnabled            = cbIndexChannel.Checked;
                contentChannel.ItemsManuallyOrdered      = cbItemsManuallyOrdered.Checked;
                contentChannel.ChildItemsManuallyOrdered = cbChildItemsManuallyOrdered.Checked;
                contentChannel.EnableRss         = cbEnableRss.Checked;
                contentChannel.ChannelUrl        = tbChannelUrl.Text;
                contentChannel.TimeToLive        = nbTimetoLive.Text.AsIntegerOrNull();
                contentChannel.ItemUrl           = tbContentChannelItemPublishingPoint.Text;
                contentChannel.IsTaggingEnabled  = cbEnableTag.Checked;
                contentChannel.ItemTagCategoryId = cbEnableTag.Checked ? cpCategory.SelectedValueAsInt() : ( int? )null;

                // Add any categories
                contentChannel.Categories.Clear();
                foreach (var categoryId in cpCategories.SelectedValuesAsInt())
                {
                    contentChannel.Categories.Add(categoryService.Get(categoryId));
                }

                // Since changes to Categories isn't tracked by ChangeTracker, set the ModifiedDateTime just in case Categories changed
                contentChannel.ModifiedDateTime = RockDateTime.Now;

                contentChannel.ChildContentChannels = new List <ContentChannel>();
                contentChannel.ChildContentChannels.Clear();
                foreach (var item in ChildContentChannelsList)
                {
                    var childContentChannel = contentChannelService.Get(item);
                    if (childContentChannel != null)
                    {
                        contentChannel.ChildContentChannels.Add(childContentChannel);
                    }
                }

                contentChannel.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentChannel);

                if (!Page.IsValid || !contentChannel.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentChannel.SaveAttributeValues(rockContext);

                    foreach (var item in new ContentChannelItemService(rockContext)
                             .Queryable()
                             .Where(i =>
                                    i.ContentChannelId == contentChannel.Id &&
                                    i.ContentChannelTypeId != contentChannel.ContentChannelTypeId
                                    ))
                    {
                        item.ContentChannelTypeId = contentChannel.ContentChannelTypeId;
                    }

                    rockContext.SaveChanges();

                    // Save the Item Attributes
                    int entityTypeId = EntityTypeCache.Get(typeof(ContentChannelItem)).Id;
                    SaveAttributes(contentChannel.Id, entityTypeId, ItemAttributesState, rockContext);
                });

                var pageReference = RockPage.PageReference;
                pageReference.Parameters.AddOrReplace("ContentChannelId", contentChannel.Id.ToString());
                Response.Redirect(pageReference.BuildUrl(), false);
            }
        }
        /// <summary>
        /// Handles the SaveClick event of the mdContentComponentConfig control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void mdContentComponentConfig_SaveClick(object sender, EventArgs e)
        {
            var rockContext = new RockContext();

            var dataViewFilter = ReportingHelper.GetFilterFromControls(phFilters);

            if (dataViewFilter != null)
            {
                // update Guids since we are creating a new dataFilter and children and deleting the old one
                SetNewDataFilterGuids(dataViewFilter);

                if (!Page.IsValid)
                {
                    return;
                }

                if (!dataViewFilter.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                DataViewFilterService dataViewFilterService = new DataViewFilterService(rockContext);

                int?dataViewFilterId = hfDataFilterId.Value.AsIntegerOrNull();
                if (dataViewFilterId.HasValue)
                {
                    var oldDataViewFilter = dataViewFilterService.Get(dataViewFilterId.Value);
                    DeleteDataViewFilter(oldDataViewFilter, dataViewFilterService);
                }

                dataViewFilterService.Add(dataViewFilter);
            }

            rockContext.SaveChanges();

            ContentChannelService contentChannelService = new ContentChannelService(rockContext);
            Guid?          contentChannelGuid           = this.GetAttributeValue("ContentChannel").AsGuidOrNull();
            ContentChannel contentChannel = null;

            if (contentChannelGuid.HasValue)
            {
                contentChannel = contentChannelService.Get(contentChannelGuid.Value);
            }

            if (contentChannel == null)
            {
                contentChannel = new ContentChannel();
                contentChannel.ContentChannelTypeId = this.ContentChannelTypeId;
                contentChannelService.Add(contentChannel);
            }

            contentChannel.LoadAttributes(rockContext);
            avcContentChannelAttributes.GetEditValues(contentChannel);

            contentChannel.Name = tbComponentName.Text;
            rockContext.SaveChanges();
            contentChannel.SaveAttributeValues(rockContext);

            this.SetAttributeValue("ContentChannel", contentChannel.Guid.ToString());

            this.SetAttributeValue("ItemCacheDuration", nbItemCacheDuration.Text);

            int? contentComponentTemplateValueId   = dvpContentComponentTemplate.SelectedValue.AsInteger();
            Guid?contentComponentTemplateValueGuid = null;

            if (contentComponentTemplateValueId.HasValue)
            {
                var contentComponentTemplate = DefinedValueCache.Get(contentComponentTemplateValueId.Value);
                if (contentComponentTemplate != null)
                {
                    contentComponentTemplateValueGuid = contentComponentTemplate.Guid;
                }
            }

            this.SetAttributeValue("ContentComponentTemplate", contentComponentTemplateValueGuid.ToString());
            this.SetAttributeValue("AllowMultipleContentItems", cbAllowMultipleContentItems.Checked.ToString());
            this.SetAttributeValue("OutputCacheDuration", nbOutputCacheDuration.Text);
            this.SetAttributeValue("CacheTags", cblCacheTags.SelectedValues.AsDelimited(","));
            if (dataViewFilter != null)
            {
                this.SetAttributeValue("FilterId", dataViewFilter.Id.ToString());
            }
            else
            {
                this.SetAttributeValue("FilterId", null);
            }

            this.SaveAttributeValues();

            var block = new BlockService(rockContext).Get(this.BlockId);

            block.PreHtml  = cePreHtml.Text;
            block.PostHtml = cePostHtml.Text;
            rockContext.SaveChanges();

            mdContentComponentConfig.Hide();
            pnlContentComponentConfig.Visible = false;

            RemoveCacheItem(OUTPUT_CACHE_KEY);
            RemoveCacheItem(ITEM_CACHE_KEY);

            // reload the page to make sure we have a clean load
            NavigateToCurrentPageReference();
        }
Exemplo n.º 3
0
        /// <summary>
        /// Handles the Click event of the lbSave control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs" /> instance containing the event data.</param>
        protected void lbSave_Click(object sender, EventArgs e)
        {
            var            rockContext = new RockContext();
            ContentChannel contentChannel;

            ContentChannelService contentChannelService = new ContentChannelService(rockContext);

            int contentChannelId = hfId.Value.AsInteger();

            if (contentChannelId == 0)
            {
                contentChannel = new ContentChannel {
                    Id = 0
                };
                contentChannelService.Add(contentChannel);
            }
            else
            {
                contentChannel = contentChannelService.Get(contentChannelId);
            }

            if (contentChannel != null)
            {
                contentChannel.Name                      = tbName.Text;
                contentChannel.Description               = tbDescription.Text;
                contentChannel.ContentChannelTypeId      = ddlChannelType.SelectedValueAsInt() ?? 0;
                contentChannel.ContentControlType        = ddlContentControlType.SelectedValueAsEnum <ContentControlType>();
                contentChannel.RootImageDirectory        = tbRootImageDirectory.Visible ? tbRootImageDirectory.Text : string.Empty;
                contentChannel.IconCssClass              = tbIconCssClass.Text;
                contentChannel.RequiresApproval          = cbRequireApproval.Checked;
                contentChannel.ItemsManuallyOrdered      = cbItemsManuallyOrdered.Checked;
                contentChannel.ChildItemsManuallyOrdered = cbChildItemsManuallyOrdered.Checked;
                contentChannel.EnableRss                 = cbEnableRss.Checked;
                contentChannel.ChannelUrl                = tbChannelUrl.Text;
                contentChannel.ItemUrl                   = tbItemUrl.Text;
                contentChannel.TimeToLive                = nbTimetoLive.Text.AsIntegerOrNull();

                contentChannel.ChildContentChannels = new List <ContentChannel>();
                contentChannel.ChildContentChannels.Clear();
                foreach (var item in ChildContentChannelsList)
                {
                    var childContentChannel = contentChannelService.Get(item);
                    if (childContentChannel != null)
                    {
                        contentChannel.ChildContentChannels.Add(childContentChannel);
                    }
                }

                contentChannel.LoadAttributes(rockContext);
                Rock.Attribute.Helper.GetEditValues(phAttributes, contentChannel);

                if (!Page.IsValid || !contentChannel.IsValid)
                {
                    // Controls will render the error messages
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    rockContext.SaveChanges();
                    contentChannel.SaveAttributeValues(rockContext);

                    foreach (var item in new ContentChannelItemService(rockContext)
                             .Queryable()
                             .Where(i =>
                                    i.ContentChannelId == contentChannel.Id &&
                                    i.ContentChannelTypeId != contentChannel.ContentChannelTypeId
                                    ))
                    {
                        item.ContentChannelTypeId = contentChannel.ContentChannelTypeId;
                    }

                    rockContext.SaveChanges();

                    // Save the Item Attributes
                    int entityTypeId = EntityTypeCache.Read(typeof(ContentChannelItem)).Id;
                    SaveAttributes(contentChannel.Id, entityTypeId, ItemAttributesState, rockContext);
                });

                var pageReference = RockPage.PageReference;
                pageReference.Parameters.AddOrReplace("contentChannelId", contentChannel.Id.ToString());
                Response.Redirect(pageReference.BuildUrl(), false);
            }
        }