Rock.Model.SiteService.GetByDefaultPageId C# (CSharp) Method

GetByDefaultPageId() public method

Returns a collection of Rock.Model.Site entities that by their Default Page's PageId.
public GetByDefaultPageId ( int defaultPageId ) : IQueryable
defaultPageId int An containing the Id of the default to search by. This /// value is nullable.
return IQueryable
        public IQueryable<Site> GetByDefaultPageId( int? defaultPageId )
        {
            return Queryable().Where( t => ( t.DefaultPageId == defaultPageId || ( defaultPageId == null && t.DefaultPageId == null ) ) );
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var rockContext = new RockContext();

            var htmlContentService = new HtmlContentService( rockContext );
            var htmlContent = htmlContentService.Queryable();

            string pageName = "";
            string siteName = "";
            var htmlList = new List<HtmlApproval>();
            foreach ( var content in htmlContent )
            {
                content.Block.LoadAttributes();
                var blah = content.Block.GetAttributeValue( "RequireApproval" );
                if ( !string.IsNullOrEmpty( blah ) && blah.ToLower() == "true" )
                {
                    var pageService = new PageService( rockContext );
                    if ( content.Block.PageId != null )
                    {
                        var page = pageService.Get( (int)content.Block.PageId );
                        if ( page != null )
                        {
                            pageName = page.InternalName;
                            while ( page.ParentPageId != null )
                            {
                                page = pageService.Get( (int)page.ParentPageId );
                            }
                            var siteService = new SiteService( rockContext );
                            siteName = siteService.GetByDefaultPageId( page.Id ).Select( s => s.Name ).FirstOrDefault();
                        }
                    }

                    var htmlApprovalClass = new HtmlApproval();
                    htmlApprovalClass.SiteName = siteName;
                    htmlApprovalClass.PageName = pageName;
                    htmlApprovalClass.Block = content.Block;
                    htmlApprovalClass.BlockId = content.BlockId;
                    htmlApprovalClass.Content = content.Content;
                    htmlApprovalClass.Id = content.Id;
                    htmlApprovalClass.IsApproved = content.IsApproved;
                    htmlApprovalClass.ApprovedByPerson = content.ApprovedByPerson;
                    htmlApprovalClass.ApprovedByPersonId = content.ApprovedByPersonId;
                    htmlApprovalClass.ApprovedDateTime = content.ApprovedDateTime;

                    htmlList.Add( htmlApprovalClass );
                }
            }

            // Filter by Site
            if ( ddlSiteFilter.SelectedIndex > 0 )
            {
                if ( ddlSiteFilter.SelectedValue.ToLower() != "all" )
                {
                    htmlList = htmlList.Where( h => h.SiteName == ddlSiteFilter.SelectedValue ).ToList();
                }
            }

            // Filter by approved/unapproved
            if ( ddlApprovedFilter.SelectedIndex > -1 )
            {
                if ( ddlApprovedFilter.SelectedValue.ToLower() == "unapproved" )
                {
                    htmlList = htmlList.Where( a => a.IsApproved == false ).ToList();
                }
                else if ( ddlApprovedFilter.SelectedValue.ToLower() == "approved" )
                {
                    htmlList = htmlList.Where( a => a.IsApproved == true ).ToList();
                }
            }

            // Filter by the person that approved the content
            if ( _canApprove )
            {
                int personId = 0;
                if ( int.TryParse( gContentListFilter.GetUserPreference( "Approved By" ), out personId ) && personId != 0 )
                {
                    htmlList = htmlList.Where( a => a.ApprovedByPersonId.HasValue && a.ApprovedByPersonId.Value == personId ).ToList();
                }
            }

            SortProperty sortProperty = gContentList.SortProperty;
            if ( sortProperty != null )
            {
                gContentList.DataSource = htmlList.AsQueryable().Sort( sortProperty ).ToList();
            }
            else
            {
                gContentList.DataSource = htmlList.OrderBy( h => h.Id ).ToList();
            }

            gContentList.DataBind();
        }