GetByPageId() public method

Returns an enumerable collection of Rock.Model.PageView entities by the Id of the Rock.Model.Page
public GetByPageId ( int pageId ) : IEnumerable
pageId int The page identifier.
return IEnumerable
        /// <summary>
        /// Handles the Delete event of the rGrid 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 rGrid_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            var pageService = new PageService( rockContext );
            var pageViewService = new PageViewService( rockContext );
            var siteService = new SiteService( rockContext );

            var page = pageService.Get( e.RowKeyId );
            if ( page != null )
            {
                string errorMessage = string.Empty;
                if ( !pageService.CanDelete( page, out errorMessage ) )
                {
                    mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                foreach ( var site in siteService.Queryable() )
                {
                    if ( site.DefaultPageId == page.Id )
                    {
                        site.DefaultPageId = null;
                        site.DefaultPageRouteId = null;
                    }

                    if ( site.LoginPageId == page.Id )
                    {
                        site.LoginPageId = null;
                        site.LoginPageRouteId = null;
                    }

                    if ( site.RegistrationPageId == page.Id )
                    {
                        site.RegistrationPageId = null;
                        site.RegistrationPageRouteId = null;
                    }
                }

                foreach ( var pageView in pageViewService.GetByPageId( page.Id ) )
                {
                    pageView.Page = null;
                    pageView.PageId = null;
                }

                pageService.Delete( page );

                rockContext.SaveChanges();

                Rock.Web.Cache.PageCache.Flush( page.Id );

                if ( _page != null )
                {
                    _page.FlushChildPages();
                }
            }

            BindGrid();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handles the Delete event of the gPages 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 gPages_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            PageService pageService = new PageService( rockContext );
            var pageViewService = new PageViewService(rockContext);
            var siteService = new SiteService(rockContext);

            Rock.Model.Page page = pageService.Get( new Guid( e.RowKeyValue.ToString() ) );
            if ( page != null )
            {
                string errorMessage;
                if ( !pageService.CanDelete( page, out errorMessage, includeSecondLvl: true ) )
                {
                    mdGridWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                foreach (var site in siteService.Queryable())
                {
                    if (site.DefaultPageId == page.Id)
                    {
                        site.DefaultPageId = null;
                        site.DefaultPageRouteId = null;
                    }
                    if (site.LoginPageId == page.Id)
                    {
                        site.LoginPageId = null;
                        site.LoginPageRouteId = null;
                    }
                    if (site.RegistrationPageId == page.Id)
                    {
                        site.RegistrationPageId = null;
                        site.RegistrationPageRouteId = null;
                    }
                }

                foreach (var pageView in pageViewService.GetByPageId(page.Id))
                {
                    pageView.Page = null;
                    pageView.PageId = null;
                }

                pageService.Delete( page );

                rockContext.SaveChanges();

                PageCache.Flush( page.Id );
            }

            BindPagesGrid();
        }
Ejemplo n.º 3
0
        protected void rGrid_Delete( object sender, RowEventArgs e )
        {
            var rockContext = new RockContext();
            var pageService = new PageService( rockContext );
            var pageViewService = new PageViewService( rockContext );
            var siteService = new SiteService( rockContext );

            var page = pageService.Get( (int)rGrid.DataKeys[e.RowIndex]["id"] );
            if ( page != null )
            {
                string errorMessage = string.Empty;
                if ( !pageService.CanDelete( page, out errorMessage ) )
                {
                    //errorMessage = "The page is the parent page of another page.";
                    mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                foreach ( var site in siteService.Queryable() )
                {
                    if ( site.DefaultPageId == page.Id )
                    {
                        site.DefaultPageId = null;
                        site.DefaultPageRouteId = null;
                    }
                    if ( site.LoginPageId == page.Id )
                    {
                        site.LoginPageId = null;
                        site.LoginPageRouteId = null;
                    }
                    if ( site.RegistrationPageId == page.Id )
                    {
                        site.RegistrationPageId = null;
                        site.RegistrationPageRouteId = null;
                    }
                }

                // TODO: Could be thousands of page views.  Can we set this up as cascade?
                foreach( var pageView in pageViewService.GetByPageId(page.Id))
                {
                    pageViewService.Delete( pageView );
                }
                pageService.Delete( page );

                rockContext.SaveChanges();

                Rock.Web.Cache.PageCache.Flush( page.Id );

                if ( _page != null )
                {
                    _page.FlushChildPages();
                }
            }

            BindGrid();
        }