示例#1
0
        /// <summary>
        /// Handles the Click event of the deleteField control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs"/> instance containing the event data.</param>
        /// <exception cref="System.NotImplementedException"></exception>
        void gContentChannelItems_Delete(object sender, RowEventArgs e)
        {
            var rockContext                   = new RockContext();
            var contentItemService            = new ContentChannelItemService(rockContext);
            var contentItemAssociationService = new ContentChannelItemAssociationService(rockContext);
            var contentItemSlugService        = new ContentChannelItemSlugService(rockContext);

            var contentItem = contentItemService.Get(e.RowKeyId);

            if (contentItem != null)
            {
                string errorMessage;
                if (!contentItemService.CanDelete(contentItem, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    contentItemAssociationService.DeleteRange(contentItem.ChildItems);
                    contentItemAssociationService.DeleteRange(contentItem.ParentItems);
                    contentItemService.Delete(contentItem);
                    rockContext.SaveChanges();
                });
            }

            GetData();
        }
        /// <summary>
        /// Handles the DeleteClick event of the gContentChannelItems control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="Rock.Web.UI.Controls.RowEventArgs"/> instance containing the event data.</param>
        protected void gContentChannelItems_DeleteClick(object sender, Rock.Web.UI.Controls.RowEventArgs e)
        {
            var rockContext                   = new RockContext();
            var contentItemService            = new ContentChannelItemService(rockContext);
            var contentItemAssociationService = new ContentChannelItemAssociationService(rockContext);
            var contentItemSlugService        = new ContentChannelItemSlugService(rockContext);

            ContentChannelItem contentItem = contentItemService.Get(e.RowKeyId);

            if (contentItem != null)
            {
                string errorMessage;
                if (!contentItemService.CanDelete(contentItem, out errorMessage))
                {
                    mdGridWarning.Show(errorMessage, ModalAlertType.Information);
                    return;
                }

                rockContext.WrapTransaction(() =>
                {
                    contentItemAssociationService.DeleteRange(contentItem.ChildItems);
                    contentItemAssociationService.DeleteRange(contentItem.ParentItems);
                    contentItemService.Delete(contentItem);
                    rockContext.SaveChanges();
                });
            }

            BindContentChannelItemsGrid();

            // edit whatever the first item is, or create a new one
            var contentChannel       = GetContentChannel();
            var contentChannelItemId = new ContentChannelItemService(rockContext).Queryable().Where(a => a.ContentChannelId == contentChannel.Id).OrderBy(a => a.Order).ThenBy(a => a.Title).Select(a => ( int? )a.Id).FirstOrDefault();

            EditContentChannelItem(contentChannelItemId);
        }
        /// <summary>
        /// Handles the Delete event of the gItems control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RowEventArgs" /> instance containing the event data.</param>
        protected void gItems_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            var contentItemService = new ContentChannelItemService( rockContext );
            var contentItemAssociationService = new ContentChannelItemAssociationService( rockContext );

            ContentChannelItem contentItem = contentItemService.Get( e.RowKeyId );

            if ( contentItem != null )
            {
                string errorMessage;
                if ( !contentItemService.CanDelete( contentItem, out errorMessage ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                    return;
                }

                rockContext.WrapTransaction( () =>
                {
                    contentItemAssociationService.DeleteRange( contentItem.ChildItems );
                    contentItemAssociationService.DeleteRange( contentItem.ParentItems );
                    contentItemService.Delete( contentItem );
                    rockContext.SaveChanges();
                } );
            }

            BindGrid();
        }