public ActionResult Index(CommentIndexOptions options) { // Default options if (options == null) options = new CommentIndexOptions(); // Filtering IEnumerable<Comment> 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 entries = comments.Select(comment => CreateCommentEntry(comment.Record)).ToList(); var model = new CommentsIndexViewModel {Comments = entries, Options = options}; return View(model); } catch (Exception exception) { Services.Notifier.Error(T("Listing comments failed: " + exception.Message)); 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> 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()); } }