/// <summary>
        /// Binds the group members grid.
        /// </summary>
        protected void BindLayoutsGrid()
        {
            pnlLayouts.Visible = false;

            int siteId = PageParameter( "siteId" ).AsInteger() ?? 0;
            if ( siteId == 0 )
            {
                // quit if the siteId can't be determined
                return;
            }

            hfSiteId.SetValue( siteId );

            pnlLayouts.Visible = true;

            // Add any missing layouts
            LayoutService.RegisterLayouts( Request.MapPath( "~" ), SiteCache.Read( siteId ) );

            LayoutService layoutService = new LayoutService( new RockContext() );
            var qry = layoutService.Queryable().Where( a => a.SiteId.Equals( siteId ) );

            SortProperty sortProperty = gLayouts.SortProperty;

            if ( sortProperty != null )
            {
                gLayouts.DataSource = qry.Sort( sortProperty ).ToList();
            }
            else
            {
                gLayouts.DataSource = qry.OrderBy( l => l.Name ).ToList();
            }

            gLayouts.DataBind();
        }
Esempio n. 2
0
 /// <summary>
 /// Binds the filter.
 /// </summary>
 private void BindFilter()
 {
     int siteId = PageParameter( "siteId" ).AsInteger();
     if ( siteId == 0 )
     {
         // quit if the siteId can't be determined
         return;
     }
     LayoutService.RegisterLayouts( Request.MapPath( "~" ), SiteCache.Read( siteId ) );
     LayoutService layoutService = new LayoutService( new RockContext() );
     var layouts = layoutService.Queryable().Where( a => a.SiteId.Equals( siteId ) ).ToList();
     ddlLayoutFilter.DataSource = layouts;
     ddlLayoutFilter.DataBind();
     ddlLayoutFilter.Items.Insert( 0, Rock.Constants.All.ListItem );
     ddlLayoutFilter.Visible = layouts.Any();
     ddlLayoutFilter.SetValue( gPagesFilter.GetUserPreference( "Layout" ) );
 }
Esempio n. 3
0
        /// <summary>
        /// Handles the Click event of the btnDeleteConfirm 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 btnDeleteConfirm_Click( object sender, EventArgs e )
        {
            bool canDelete = false;

            var rockContext = new RockContext();
            SiteService siteService = new SiteService( rockContext );
            Site site = siteService.Get( int.Parse( hfSiteId.Value ) );
            LayoutService layoutService = new LayoutService( rockContext );
            PageService pageService = new PageService( rockContext );
            PageViewService pageViewService = new PageViewService( rockContext );

            if ( site != null )
            {
                var sitePages = new List<int> {
                    site.DefaultPageId ?? -1,
                    site.LoginPageId ?? -1,
                    site.RegistrationPageId ?? -1,
                    site.PageNotFoundPageId ?? -1
                };

                foreach ( var pageView in pageViewService
                    .Queryable()
                    .Where( t =>
                        t.Page != null &&
                        t.Page.Layout != null &&
                        t.Page.Layout.SiteId == site.Id ) )
                {
                    pageView.Page = null;
                    pageView.PageId = null;
                }

                var pageQry = pageService.Queryable( "Layout" )
                    .Where( t =>
                        t.Layout.SiteId == site.Id ||
                        sitePages.Contains( t.Id ) );

                pageService.DeleteRange( pageQry );

                var layoutQry = layoutService.Queryable()
                    .Where( l =>
                        l.SiteId == site.Id );
                layoutService.DeleteRange( layoutQry );
                rockContext.SaveChanges( true );

                string errorMessage;
                canDelete = siteService.CanDelete( site, out errorMessage, includeSecondLvl: true );
                if ( !canDelete )
                {
                    mdDeleteWarning.Show( errorMessage, ModalAlertType.Alert );
                    return;
                }

                siteService.Delete( site );

                rockContext.SaveChanges();

                SiteCache.Flush( site.Id );
            }

            NavigateToParentPage();
        }
Esempio n. 4
0
        /// <summary>
        /// Binds the pages grid.
        /// </summary>
        protected void BindPagesGrid()
        {
            pnlPages.Visible = false;
            int siteId = PageParameter( "siteId" ).AsInteger() ?? 0;
            if ( siteId == 0 )
            {
                // quit if the siteId can't be determined
                return;
            }

            hfSiteId.SetValue( siteId );
            pnlPages.Visible = true;

            LayoutService layoutService = new LayoutService();
            layoutService.RegisterLayouts( Request.MapPath( "~" ), SiteCache.Read( siteId ), CurrentPersonId );
            var layouts = layoutService.Queryable().Where( a => a.SiteId.Equals( siteId ) ).Select( a => a.Id ).ToList();

            var siteService = new SiteService();
            var pageId = siteService.Get( siteId ).DefaultPageId;

            var pageService = new PageService();
            var qry = pageService.GetAllDescendents( (int)pageId ).AsQueryable().Where( a => layouts.Contains(a.LayoutId) );

            string layoutFilter = gPagesFilter.GetUserPreference( "Layout" );
            if ( !string.IsNullOrWhiteSpace( layoutFilter ) && layoutFilter != Rock.Constants.All.Text )
            {
                qry = qry.Where( a => a.Layout.ToString() == layoutFilter );
            }

            SortProperty sortProperty = gPages.SortProperty;
            if ( sortProperty != null )
            {
                qry = qry.Sort( sortProperty );
            }
            else
            {
                qry = qry.OrderBy( q => q.Id );
            }

            gPages.DataSource = qry.ToList();
            gPages.DataBind();
        }