コード例 #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();
            ContentChannelType contentType;

            ContentChannelTypeService contentTypeService = new ContentChannelTypeService(rockContext);

            int contentTypeId = int.Parse(hfId.Value);

            if (contentTypeId == 0)
            {
                contentType = new ContentChannelType();
                contentTypeService.Add(contentType);
                contentType.CreatedByPersonAliasId = CurrentPersonAliasId;
                contentType.CreatedDateTime        = RockDateTime.Now;
            }
            else
            {
                contentType = contentTypeService.Get(contentTypeId);
                contentType.ModifiedByPersonAliasId = CurrentPersonAliasId;
                contentType.ModifiedDateTime        = RockDateTime.Now;
            }

            if (contentType != null)
            {
                contentType.Name                = tbName.Text;
                contentType.DateRangeType       = ddlDateRangeType.SelectedValue.ConvertToEnum <ContentChannelDateType>();
                contentType.IncludeTime         = cbIncludeTime.Checked;
                contentType.DisablePriority     = cbDisablePriority.Checked;
                contentType.DisableContentField = cbDisableContentField.Checked;
                contentType.DisableStatus       = cbDisableStatus.Checked;
                contentType.ShowInChannelList   = cbShowInChannelList.Checked;

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

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

                    // get it back to make sure we have a good Id for it for the Attributes
                    contentType = contentTypeService.Get(contentType.Guid);

                    // Save the Channel Attributes
                    int entityTypeId = EntityTypeCache.Get(typeof(ContentChannel)).Id;
                    SaveAttributes(contentType.Id, entityTypeId, ChannelAttributesState, rockContext);

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

                NavigateToParentPage();
            }
        }
コード例 #2
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();
            ContentChannelType contentType;

            ContentChannelTypeService contentTypeService = new ContentChannelTypeService(rockContext);

            int contentTypeId = int.Parse(hfId.Value);

            if (contentTypeId == 0)
            {
                contentType = new ContentChannelType();
                contentTypeService.Add(contentType);
            }
            else
            {
                contentType = contentTypeService.Get(contentTypeId);
            }

            if (contentType != null)
            {
                contentType.Name            = tbName.Text;
                contentType.DateRangeType   = (ContentChannelDateType)int.Parse(ddlDateRangeType.SelectedValue);
                contentType.DisablePriority = cbDisablePriority.Checked;

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

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

                    // get it back to make sure we have a good Id for it for the Attributes
                    contentType = contentTypeService.Get(contentType.Guid);

                    // Save the Channel Attributes
                    int entityTypeId = EntityTypeCache.Read(typeof(ContentChannel)).Id;
                    SaveAttributes(contentType.Id, entityTypeId, ChannelAttributesState, rockContext);

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

                NavigateToParentPage();
            }
        }
コード例 #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();
            ContentChannelType contentType;

            ContentChannelTypeService contentTypeService = new ContentChannelTypeService( rockContext );

            int contentTypeId = int.Parse( hfId.Value );

            if ( contentTypeId == 0 )
            {
                contentType = new ContentChannelType();
                contentTypeService.Add( contentType );
            }
            else
            {
                contentType = contentTypeService.Get( contentTypeId );
            }

            if ( contentType != null )
            {
                contentType.Name = tbName.Text;
                contentType.DateRangeType = (ContentChannelDateType)int.Parse( ddlDateRangeType.SelectedValue );
                contentType.IncludeTime = cbIncludeTime.Checked;
                contentType.DisablePriority = cbDisablePriority.Checked;

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

                rockContext.WrapTransaction( () =>
                {

                    rockContext.SaveChanges();

                    // get it back to make sure we have a good Id for it for the Attributes
                    contentType = contentTypeService.Get( contentType.Guid );

                    // Save the Channel Attributes
                    int entityTypeId = EntityTypeCache.Read( typeof( ContentChannel ) ).Id;
                    SaveAttributes( contentType.Id, entityTypeId, ChannelAttributesState, rockContext );

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

                } );

                NavigateToParentPage();
            }
        }