Пример #1
0
        /// <summary>
        /// Binds the grid.
        /// </summary>
        private void BindGrid()
        {
            var htmlContentService = new HtmlContentService();
            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();
                    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();
                            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();
        }