/// <summary>
        /// Handles the Click event of the DeleteLayout 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 DeleteLayout_Click( object sender, Rock.Web.UI.Controls.RowEventArgs e )
        {
            bool canDelete = false;

            var rockContext = new RockContext();
            LayoutService layoutService = new LayoutService(rockContext);

            Layout layout = layoutService.Get( e.RowKeyId );
            if ( layout != null )
            {
                string errorMessage;
                canDelete = layoutService.CanDelete( layout, out errorMessage );
                if ( !canDelete )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                int siteId = layout.SiteId;

                layoutService.Delete( layout );
                rockContext.SaveChanges();

                LayoutCache.Flush( e.RowKeyId );
            }

            BindLayoutsGrid();
        }
Exemple #2
0
        /// <summary>
        /// Handles the Click event of the DeleteLayout 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 DeleteLayout_Click( object sender, Rock.Web.UI.Controls.RowEventArgs e )
        {
            RockTransactionScope.WrapTransaction( () =>
            {
                LayoutService layoutService = new LayoutService();
                Layout layout = layoutService.Get( e.RowKeyId );
                if ( layout != null )
                {
                    string errorMessage;
                    if ( !layoutService.CanDelete( layout, out errorMessage ) )
                    {
                        mdGridWarning.Show( errorMessage, ModalAlertType.Information );
                        return;
                    }

                    int siteId = layout.SiteId;

                    layoutService.Delete( layout, CurrentPersonId );
                    layoutService.Save( layout, CurrentPersonId );

                    LayoutCache.Flush( e.RowKeyId );
                }
            } );

            BindLayoutsGrid();
        }