public ActionResult Comments(int? filterByBlogPostId, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog)) return AccessDeniedView(); IList<BlogComment> comments; if (filterByBlogPostId.HasValue) { //filter comments by blog var blogPost = _blogService.GetBlogPostById(filterByBlogPostId.Value); comments = blogPost.BlogComments.OrderBy(bc => bc.CreatedOnUtc).ToList(); } else { //load all blog comments comments = _customerContentService.GetAllCustomerContent<BlogComment>(0, null); } var gridModel = new GridModel<BlogCommentModel> { Data = comments.PagedForCommand(command).Select(blogComment => { var commentModel = new BlogCommentModel(); commentModel.Id = blogComment.Id; commentModel.BlogPostId = blogComment.BlogPostId; commentModel.BlogPostTitle = blogComment.BlogPost.Title; commentModel.CustomerId = blogComment.CustomerId; commentModel.IpAddress = blogComment.IpAddress; commentModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc); commentModel.Comment = Core.Html.HtmlHelper.FormatText(blogComment.CommentText, false, true, false, false, false, false); return commentModel; }), Total = comments.Count, }; return new JsonResult { Data = gridModel }; }
public ActionResult Comments(int? filterByBlogPostId, DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog)) return AccessDeniedView(); IList<BlogComment> comments; if (filterByBlogPostId.HasValue) { //filter comments by blog var blogPost = _blogService.GetBlogPostById(filterByBlogPostId.Value); comments = blogPost.BlogComments.OrderBy(bc => bc.CreatedOnUtc).ToList(); } else { //load all blog comments comments = _blogService.GetAllComments(0); } var gridModel = new DataSourceResult { Data = comments.PagedForCommand(command).Select(blogComment => { var commentModel = new BlogCommentModel(); commentModel.Id = blogComment.Id; commentModel.BlogPostId = blogComment.BlogPostId; commentModel.BlogPostTitle = blogComment.BlogPost.Title; commentModel.CustomerId = blogComment.CustomerId; var customer = blogComment.Customer; commentModel.CustomerInfo = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest"); commentModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc); commentModel.Comment = Core.Html.HtmlHelper.FormatText(blogComment.CommentText, false, true, false, false, false, false); return commentModel; }), Total = comments.Count, }; return Json(gridModel); }