public ActionResult Index(CommentIndexOptions options, PagerParameters pagerParameters) { Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); // Default options if (options == null) { options = new CommentIndexOptions(); } // Filtering IContentQuery <CommentPart, CommentPartRecord> comments; try { switch (options.Filter) { case CommentIndexFilter.All: comments = _commentService.GetComments(); break; case CommentIndexFilter.Approved: comments = _commentService.GetComments(CommentStatus.Approved); break; case CommentIndexFilter.Pending: comments = _commentService.GetComments(CommentStatus.Pending); break; case CommentIndexFilter.Spam: comments = _commentService.GetComments(CommentStatus.Spam); break; default: throw new ArgumentOutOfRangeException(); } var pagerShape = Shape.Pager(pager).TotalItemCount(comments.Count()); var entries = comments .OrderByDescending <CommentPartRecord, DateTime?>(cpr => cpr.CommentDateUtc) .Slice(pager.GetStartIndex(), pager.PageSize) .ToList() .Select(comment => CreateCommentEntry(comment.Record)); var model = new CommentsIndexViewModel { Comments = entries.ToList(), Options = options, Pager = pagerShape }; return(View(model)); } catch (Exception exception) { this.Error(exception, T("Listing comments failed: {0}", exception.Message), Logger, Services.Notifier); return(View(new CommentsIndexViewModel())); } }
public ActionResult Index(CommentIndexOptions options, PagerParameters pagerParameters) { Pager pager = new Pager(_siteService.GetSiteSettings(), pagerParameters); // Default options if (options == null) { options = new CommentIndexOptions(); } // Filtering IContentQuery <CommentPart, CommentPartRecord> commentsQuery; switch (options.Filter) { case CommentIndexFilter.All: commentsQuery = _commentService.GetComments(); break; case CommentIndexFilter.Approved: commentsQuery = _commentService.GetComments(CommentStatus.Approved); break; case CommentIndexFilter.Pending: commentsQuery = _commentService.GetComments(CommentStatus.Pending); break; default: throw new ArgumentOutOfRangeException(); } var pagerShape = Shape.Pager(pager).TotalItemCount(commentsQuery.Count()); var entries = commentsQuery .OrderByDescending <CommentPartRecord>(cpr => cpr.CommentDateUtc) .Slice(pager.GetStartIndex(), pager.PageSize) .ToList() .Select(CreateCommentEntry); var model = new CommentsIndexViewModel { Comments = entries.ToList(), Options = options, Pager = pagerShape }; return(View(model)); }