public ActionResult Details(FormCollection input) { var viewModel = new CommentsDetailsViewModel { Comments = new List<CommentEntry>(), Options = new CommentDetailsOptions() }; UpdateModel(viewModel); try { IEnumerable<CommentEntry> checkedEntries = viewModel.Comments.Where(c => c.IsChecked); switch (viewModel.Options.BulkAction) { case CommentDetailsBulkAction.None: break; case CommentDetailsBulkAction.MarkAsSpam: if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) return new HttpUnauthorizedResult(); //TODO: Transaction foreach (CommentEntry entry in checkedEntries) { _commentService.MarkCommentAsSpam(entry.Comment.Id); } break; case CommentDetailsBulkAction.Unapprove: if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) return new HttpUnauthorizedResult(); foreach (CommentEntry entry in checkedEntries) { _commentService.UnapproveComment(entry.Comment.Id); } break; case CommentDetailsBulkAction.Approve: if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) return new HttpUnauthorizedResult(); foreach (CommentEntry entry in checkedEntries) { _commentService.ApproveComment(entry.Comment.Id); } break; case CommentDetailsBulkAction.Delete: if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't delete comment"))) return new HttpUnauthorizedResult(); foreach (CommentEntry entry in checkedEntries) { _commentService.DeleteComment(entry.Comment.Id); } break; default: throw new ArgumentOutOfRangeException(); } } catch (Exception exception) { this.Error(exception, T("Editing comments failed: {0}", exception.Message), Logger, Services.Notifier); return Details(viewModel.CommentedItemId, viewModel.Options); } return RedirectToAction("Index"); }
public ActionResult Details(int id, CommentDetailsOptions options) { // Default options if (options == null) options = new CommentDetailsOptions(); // Filtering IContentQuery<CommentPart, CommentPartRecord> comments; try { switch (options.Filter) { case CommentDetailsFilter.All: comments = _commentService.GetCommentsForCommentedContent(id); break; case CommentDetailsFilter.Approved: comments = _commentService.GetCommentsForCommentedContent(id, CommentStatus.Approved); break; case CommentDetailsFilter.Pending: comments = _commentService.GetCommentsForCommentedContent(id, CommentStatus.Pending); break; case CommentDetailsFilter.Spam: comments = _commentService.GetCommentsForCommentedContent(id, CommentStatus.Spam); break; default: throw new ArgumentOutOfRangeException(); } var entries = comments.List().Select(comment => CreateCommentEntry(comment.Record)).ToList(); var model = new CommentsDetailsViewModel { Comments = entries, Options = options, DisplayNameForCommentedItem = _commentService.GetDisplayForCommentedContent(id) == null ? "" : _commentService.GetDisplayForCommentedContent(id).DisplayText, CommentedItemId = id, CommentsClosedOnItem = _commentService.CommentsDisabledForCommentedContent(id), }; return View(model); } catch (Exception exception) { this.Error(exception, T("Listing comments failed: {0}", exception.Message), Logger, Services.Notifier); return RedirectToAction("Index"); } }