public ActionResult Index(FormCollection input) { var viewModel = new CommentsIndexViewModel { Comments = new List <CommentEntry>(), Options = new CommentIndexOptions() }; UpdateModel(viewModel); IEnumerable <CommentEntry> checkedEntries = viewModel.Comments.Where(c => c.IsChecked); switch (viewModel.Options.BulkAction) { case CommentIndexBulkAction.None: break; case CommentIndexBulkAction.Unapprove: if (!_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) { return(new HttpUnauthorizedResult()); } //TODO: Transaction foreach (CommentEntry entry in checkedEntries) { _commentService.UnapproveComment(entry.Comment.Id); } break; case CommentIndexBulkAction.Approve: if (!_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) { return(new HttpUnauthorizedResult()); } //TODO: Transaction foreach (CommentEntry entry in checkedEntries) { _commentService.ApproveComment(entry.Comment.Id); } break; case CommentIndexBulkAction.Delete: if (!_orchardServices.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(); } return(RedirectToAction("Index")); }
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)); }
public async Task <IActionResult> BulkEdit(BulkAction bulkAction, PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Intelli.Comments.Permissions.ManageComments)) { return(Unauthorized()); } var viewModel = new CommentsIndexViewModel { Comments = new List <CommentRecord>(), Options = new SearchIndexOptions() }; if (!(await TryUpdateModelAsync(viewModel))) { return(View(viewModel)); } //todo create viewmodel with ischecked property var checkedEntries = viewModel.Comments.Take(1); // viewModel.Comments.Where(t => t.IsChecked); switch (bulkAction) { case BulkAction.None: break; case BulkAction.Delete: foreach (var entry in checkedEntries) { var commentRecord = await _commentsRepository.FindByIdAsync(entry.Id); if (commentRecord != null) { await _commentsRepository.DeleteAsync(commentRecord); _notifier.Success(H["Comment {0} has been deleted.", commentRecord.Content]); } } break; default: throw new ArgumentOutOfRangeException(); } return(RedirectToAction("Index", new { page = pagerParameters.Page, pageSize = pagerParameters.PageSize })); }
public ActionResult Index(FormCollection input) { var viewModel = new CommentsIndexViewModel { Comments = new List <CommentEntry>(), Options = new CommentIndexOptions() }; UpdateModel(viewModel); try { IEnumerable <CommentEntry> checkedEntries = viewModel.Comments.Where(c => c.IsChecked); switch (viewModel.Options.BulkAction) { case CommentIndexBulkAction.None: break; case CommentIndexBulkAction.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 CommentIndexBulkAction.Unapprove: if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) { return(new HttpUnauthorizedResult()); } //TODO: Transaction foreach (CommentEntry entry in checkedEntries) { _commentService.UnapproveComment(entry.Comment.Id); } break; case CommentIndexBulkAction.Approve: if (!Services.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) { return(new HttpUnauthorizedResult()); } //TODO: Transaction foreach (CommentEntry entry in checkedEntries) { _commentService.ApproveComment(entry.Comment.Id); } break; case CommentIndexBulkAction.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(RedirectToAction("Index", "Admin", new { options = viewModel.Options })); } return(RedirectToAction("Index")); }
public async Task <IActionResult> Index(SearchIndexOptions options, PagerParameters pagerParameters) { if (!await _authorizationService.AuthorizeAsync(User, Intelli.Comments.Permissions.ManageComments)) { return(Unauthorized()); } var siteSettings = await _siteService.GetSiteSettingsAsync(); var pager = new Pager(pagerParameters, siteSettings.PageSize); if (options == null) { options = new SearchIndexOptions(); } //var query = _session.Query<WorkflowType, WorkflowTypeIndex>(); // switch (options.Filter) // { // case WorkflowTypeFilter.All: // default: // break; // } // if (!string.IsNullOrWhiteSpace(options.Search)) // { // query = query.Where(w => w.Name.Contains(options.Search)); // } // switch (options.Order) // { // case WorkflowTypeOrder.Name: // query = query.OrderBy(u => u.Name); // break; // } // var count = await query.CountAsync(); // var workflowTypes = await query // .Skip(pager.GetStartIndex()) // .Take(pager.PageSize) // .ListAsync(); var comments = await _commentsRepository.FindAllAsync();// GetAllAsync(); var currentCommentList = comments // .Where(c => (currentUserGroupIds.Contains(c.GroupId) || c.GroupId == currentUserId) && c.Parent == null && c.CommentGroupTypeId != CommentGroupType.GroupChat) .OrderByDescending(c => c.CreatedUtc).ToList(); // var workflowTypeIds = workflowTypes.Select(x => x.WorkflowTypeId).ToList(); // var workflowGroups = (await _session.QueryIndex<WorkflowIndex>(x => x.WorkflowTypeId.IsIn(workflowTypeIds)) // .ListAsync()) // .GroupBy(x => x.WorkflowTypeId) // .ToDictionary(x => x.Key); // Maintain previous route data when generating page links. var routeData = new RouteData(); // routeData.Values.Add("Options.Filter", options.Filter); routeData.Values.Add("Options.Search", options.Search); // routeData.Values.Add("Options.Order", options.Order); var pagerShape = (await New.Pager(pager)).TotalItemCount(currentCommentList.Count).RouteData(routeData); var model = new CommentsIndexViewModel { Comments = currentCommentList, Options = options, Pager = pagerShape }; return(View(model)); }