public static List <PostComment> PaginateComments(IQueryable <vw_carrot_Comment> lstComments, int iPageNbr, int iPageSize, string SortBy) { int startRec = iPageNbr * iPageSize; SortParm srt = new SortParm(SortBy); if (String.IsNullOrEmpty(srt.SortField)) { srt.SortField = "CreateDate"; } if (String.IsNullOrEmpty(srt.SortDirection)) { srt.SortDirection = "DESC"; } lstComments = ReflectionUtilities.SortByParm <vw_carrot_Comment>(lstComments, srt.SortField, srt.SortDirection); return(lstComments.Skip(startRec).Take(iPageSize).ToList().Select(v => new PostComment(v)).ToList()); }
public static List <EditHistory> GetHistoryList(string orderBy, int pageNumber, int pageSize, Guid siteID, bool showLatestOnly, DateTime?editDate, Guid?editUserID) { SortParm srt = new SortParm(orderBy); if (String.IsNullOrEmpty(srt.SortField)) { srt.SortField = "EditDate"; } if (String.IsNullOrEmpty(srt.SortDirection)) { srt.SortDirection = "DESC"; } Guid userID = Guid.Empty; if (editUserID.HasValue) { userID = editUserID.Value; } DateTime dateStart = DateTime.UtcNow.Date.AddDays(-2); DateTime dateEnd = DateTime.UtcNow.Date.AddDays(1); if (editDate.HasValue) { dateStart = editDate.Value.Date.AddDays(-8); dateEnd = editDate.Value.Date.AddDays(1); } int startRec = pageNumber * pageSize; if (pageSize < 0 || pageSize > 200) { pageSize = 25; } if (pageNumber < 0 || pageNumber > 10000) { pageNumber = 0; } bool IsContentProp = false; srt.SortField = (from p in ReflectionUtilities.GetPropertyStrings(typeof(vw_carrot_EditHistory)) where p.ToLowerInvariant().Trim() == srt.SortField.ToLowerInvariant().Trim() select p).FirstOrDefault(); if (!String.IsNullOrEmpty(srt.SortField)) { IsContentProp = ReflectionUtilities.DoesPropertyExist(typeof(vw_carrot_EditHistory), srt.SortField); } using (CarrotCMSDataContext _db = CarrotCMSDataContext.Create()) { List <EditHistory> _history = null; IQueryable <vw_carrot_EditHistory> QueryInput = (from h in _db.vw_carrot_EditHistories where h.SiteID == siteID && (!showLatestOnly || h.IsLatestVersion == true) && (!editDate.HasValue || (h.EditDate.Date >= dateStart.Date && h.EditDate.Date <= dateEnd.Date)) && (!editUserID.HasValue || h.EditUserId == userID) select h); if (IsContentProp) { QueryInput = ReflectionUtilities.SortByParm <vw_carrot_EditHistory>(QueryInput, srt.SortField, srt.SortDirection); } else { QueryInput = (from c in QueryInput orderby c.EditDate descending where c.SiteID == siteID select c).AsQueryable(); } _history = (from h in QueryInput.Skip(startRec).Take(pageSize) select new EditHistory(h)).ToList(); return(_history); } }
public void FetchData() { base.ReadPageNbr(); string sPagePath = SiteData.CurrentScriptName; if (String.IsNullOrEmpty(this.OrderBy)) { this.InitOrderByDescending(x => x.GoLiveDate); } List <SiteNav> lstContents = new List <SiteNav>(); string sSearchTerm = String.Empty; ContentPageType.PageType viewContentType = ContentPageType.PageType.BlogEntry; if (this.IgnoreSitePath) { sPagePath = String.Format("/siteid-{0}", SiteData.CurrentSiteID); } if (SiteData.IsWebView) { if (SiteData.CurrentSite.IsSiteSearchPath && !this.IgnoreSitePath) { this.ContentType = SummaryContentType.SiteSearch; sSearchTerm = GetSearchTerm(); } } switch (this.ContentType) { case SummaryContentType.Blog: case SummaryContentType.ContentPage: case SummaryContentType.SiteSearch: this.InitOrderByDescending(x => x.GoLiveDate); break; } SortParm sp = this.ParseSort(); string sSortFld = sp.SortField; string sSortDir = sp.SortDirection; if (this.PageNumber <= 0) { this.PageNumber = 1; } using (ISiteNavHelper navHelper = SiteNavFactory.GetSiteNavHelper()) { if (SiteData.IsWebView) { switch (this.ContentType) { case SummaryContentType.Blog: viewContentType = ContentPageType.PageType.BlogEntry; this.TotalRecords = navHelper.GetFilteredContentPagedCount(SiteData.CurrentSite, sPagePath, !SecurityData.IsAuthEditor); lstContents = navHelper.GetFilteredContentPagedList(SiteData.CurrentSite, sPagePath, !SecurityData.IsAuthEditor, this.PageSize, this.PageNumberZeroIndex, sSortFld, sSortDir); break; case SummaryContentType.ChildContentPage: viewContentType = ContentPageType.PageType.ContentEntry; this.TotalRecords = navHelper.GetChildNavigationCount(SiteData.CurrentSiteID, sPagePath, !SecurityData.IsAuthEditor); lstContents = navHelper.GetLatestChildContentPagedList(SiteData.CurrentSiteID, sPagePath, !SecurityData.IsAuthEditor, this.PageSize, this.PageNumberZeroIndex, sSortFld, sSortDir); break; case SummaryContentType.ContentPage: viewContentType = ContentPageType.PageType.ContentEntry; this.TotalRecords = navHelper.GetSitePageCount(SiteData.CurrentSiteID, viewContentType, !SecurityData.IsAuthEditor); lstContents = navHelper.GetLatestContentPagedList(SiteData.CurrentSiteID, viewContentType, !SecurityData.IsAuthEditor, this.PageSize, this.PageNumberZeroIndex, sSortFld, sSortDir); break; case SummaryContentType.SpecifiedCategories: viewContentType = ContentPageType.PageType.BlogEntry; this.TotalRecords = navHelper.GetFilteredContentByIDPagedCount(SiteData.CurrentSite, null, SelectedCategorySlugs, !SecurityData.IsAuthEditor); lstContents = navHelper.GetFilteredContentByIDPagedList(SiteData.CurrentSite, null, SelectedCategorySlugs, !SecurityData.IsAuthEditor, this.PageSize, this.PageNumberZeroIndex, sSortFld, sSortDir); break; case SummaryContentType.SiteSearch: this.TotalRecords = navHelper.GetSiteSearchCount(SiteData.CurrentSiteID, sSearchTerm, !SecurityData.IsAuthEditor); lstContents = navHelper.GetLatestContentSearchList(SiteData.CurrentSiteID, sSearchTerm, !SecurityData.IsAuthEditor, this.PageSize, this.PageNumberZeroIndex, sSortFld, sSortDir); break; } } else { viewContentType = ContentPageType.PageType.ContentEntry; this.TotalRecords = navHelper.GetSitePageCount(SiteData.CurrentSiteID, viewContentType, false); lstContents = navHelper.GetLatestContentPagedList(Guid.NewGuid(), viewContentType, false, this.PageSize, this.PageNumberZeroIndex, sSortFld, sSortDir); } } lstContents.ToList().ForEach(q => CMSConfigHelper.IdentifyLinkAsInactive(q)); this.DataSource = lstContents; }