public ActionResult Comments(int? filterByNewsItemId, GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); IList<NewsComment> comments; if (filterByNewsItemId.HasValue) { //filter comments by news item var newsItem = _newsService.GetNewsById(filterByNewsItemId.Value); comments = newsItem.NewsComments.OrderBy(bc => bc.CreatedOnUtc).ToList(); } else { //load all news comments comments = _customerContentService.GetAllCustomerContent<NewsComment>(0, null); } var gridModel = new GridModel<NewsCommentModel> { Data = comments.PagedForCommand(command).Select(newsComment => { var commentModel = new NewsCommentModel(); commentModel.Id = newsComment.Id; commentModel.NewsItemId = newsComment.NewsItemId; commentModel.NewsItemTitle = newsComment.NewsItem.Title; commentModel.CustomerId = newsComment.CustomerId; commentModel.IpAddress = newsComment.IpAddress; commentModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsComment.CreatedOnUtc, DateTimeKind.Utc); commentModel.CommentTitle = newsComment.CommentTitle; commentModel.CommentText = Core.Html.HtmlHelper.FormatText(newsComment.CommentText, false, true, false, false, false, false); return commentModel; }), Total = comments.Count, }; return new JsonResult { Data = gridModel }; }
public ActionResult Comments(int? filterByNewsItemId, DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews)) return AccessDeniedView(); IList<NewsComment> comments; if (filterByNewsItemId.HasValue) { //filter comments by news item var newsItem = _newsService.GetNewsById(filterByNewsItemId.Value); comments = newsItem.NewsComments.OrderBy(bc => bc.CreatedOnUtc).ToList(); } else { //load all news comments comments = _newsService.GetAllComments(0); } var gridModel = new DataSourceResult { Data = comments.PagedForCommand(command).Select(newsComment => { var commentModel = new NewsCommentModel(); commentModel.Id = newsComment.Id; commentModel.NewsItemId = newsComment.NewsItemId; commentModel.NewsItemTitle = _newsService.GetNewsById(newsComment.NewsItemId).Title; commentModel.CustomerId = newsComment.CustomerId; var customer = EngineContext.Current.Resolve<ICustomerService>().GetCustomerById(newsComment.CustomerId); commentModel.CustomerInfo = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest"); commentModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsComment.CreatedOnUtc, DateTimeKind.Utc); commentModel.CommentTitle = newsComment.CommentTitle; commentModel.CommentText = Core.Html.HtmlHelper.FormatText(newsComment.CommentText, false, true, false, false, false, false); return commentModel; }), Total = comments.Count, }; return Json(gridModel); }