Пример #1
0
        public virtual ActionResult Comments(int?filterByNewsItemId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
            {
                return(AccessDeniedView());
            }

            ViewBag.FilterByNewsItemId = filterByNewsItemId;
            var model = new NewsCommentListModel();

            //"approved" property
            //0 - all
            //1 - approved only
            //2 - disapproved only
            model.AvailableApprovedOptions.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.ContentManagement.News.Comments.List.SearchApproved.All"), Value = "0"
            });
            model.AvailableApprovedOptions.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.ContentManagement.News.Comments.List.SearchApproved.ApprovedOnly"), Value = "1"
            });
            model.AvailableApprovedOptions.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.ContentManagement.News.Comments.List.SearchApproved.DisapprovedOnly"), Value = "2"
            });

            return(View(model));
        }
Пример #2
0
        public virtual IActionResult Comments(NewsCommentSearchModel searchModel)
        {
            //prepare model
            NewsCommentListModel model = _newsModelFactory.PrepareNewsCommentListModel(searchModel, searchModel.NewsItemId);

            return(Json(model));
        }
Пример #3
0
        /// <summary>
        /// Prepare paged news comment list model
        /// </summary>
        /// <param name="searchModel">News comment search model</param>
        /// <param name="newsItem">News item; pass null to prepare comment models for all news items</param>
        /// <returns>News comment list model</returns>
        public virtual NewsCommentListModel PrepareNewsCommentListModel(NewsCommentSearchModel searchModel, NewsItem newsItem)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter comments
            var createdOnFromValue = searchModel.CreatedOnFrom == null ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);
            var createdOnToValue = searchModel.CreatedOnTo == null ? null
                : (DateTime?)_dateTimeHelper.ConvertToUtcTime(searchModel.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);
            var isApprovedOnly = searchModel.SearchApprovedId == 0 ? null : searchModel.SearchApprovedId == 1 ? true : (bool?)false;

            //get comments
            var comments = _newsService.GetAllComments(newsItemId: newsItem?.Id,
                                                       approved: isApprovedOnly,
                                                       fromUtc: createdOnFromValue,
                                                       toUtc: createdOnToValue,
                                                       commentText: searchModel.SearchText);

            //prepare store names (to avoid loading for each comment)
            var storeNames = _storeService.GetAllStores().ToDictionary(store => store.Id, store => store.Name);

            //prepare list model
            var model = new NewsCommentListModel
            {
                Data = comments.PaginationByRequestModel(searchModel).Select(newsComment =>
                {
                    //fill in model values from the entity
                    var commentModel = new NewsCommentModel
                    {
                        Id            = newsComment.Id,
                        NewsItemId    = newsComment.NewsItemId,
                        NewsItemTitle = newsComment.NewsItem.Title,
                        CustomerId    = newsComment.CustomerId,
                        IsApproved    = newsComment.IsApproved,
                        StoreId       = newsComment.StoreId,
                        CommentTitle  = newsComment.CommentTitle
                    };

                    //convert dates to the user time
                    commentModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(newsComment.CreatedOnUtc, DateTimeKind.Utc);

                    //fill in additional values (not existing in the entity)
                    commentModel.CustomerInfo = newsComment.Customer.IsRegistered()
                        ? newsComment.Customer.Email : _localizationService.GetResource("Admin.Customers.Guest");
                    commentModel.CommentText = HtmlHelper.FormatText(newsComment.CommentText, false, true, false, false, false, false);
                    commentModel.StoreName   = storeNames.ContainsKey(newsComment.StoreId) ? storeNames[newsComment.StoreId] : "Deleted";

                    return(commentModel);
                }),
                Total = comments.Count
            };

            return(model);
        }
Пример #4
0
        /// <summary>
        /// Prepare paged news comment list model
        /// </summary>
        /// <param name="searchModel">News comment search model</param>
        /// <param name="newsItemId">News item Id; pass null to prepare comment models for all news items</param>
        /// <returns>News comment list model</returns>
        public virtual NewsCommentListModel PrepareNewsCommentListModel(NewsCommentSearchModel searchModel, int?newsItemId)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //get parameters to filter comments
            DateTime?createdOnFromValue = searchModel.CreatedOnFrom == null ? null
                : (DateTime?)searchModel.CreatedOnFrom.Value;
            DateTime?createdOnToValue = searchModel.CreatedOnTo == null ? null
                : (DateTime?)searchModel.CreatedOnTo.Value.AddDays(1);
            bool?isApprovedOnly = searchModel.SearchApprovedId == 0 ? null : searchModel.SearchApprovedId == 1 ? true : (bool?)false;

            //get comments
            var comments = _newsService.GetAllComments(newsItemId: newsItemId,
                                                       approved: isApprovedOnly,
                                                       fromUtc: createdOnFromValue,
                                                       toUtc: createdOnToValue,
                                                       commentText: searchModel.SearchText);

            //prepare list model
            NewsCommentListModel model = new NewsCommentListModel
            {
                Data = comments.PaginationByRequestModel(searchModel).Select(newsComment =>
                {
                    //fill in model values from the entity
                    NewsCommentModel commentModel = new NewsCommentModel
                    {
                        Id           = newsComment.Id,
                        NewsItemId   = newsComment.NewsItemId,
                        CustomerId   = newsComment.CustomerId == 0 ? 5 : newsComment.CustomerId,
                        IsApproved   = newsComment.IsApproved,
                        CommentTitle = newsComment.CommentTitle,
                        CreatedOn    = newsComment.CreatedOnUtc,
                    };
                    if (newsComment.NewsItemId != 0)
                    {
                        commentModel.NewsItemTitle = _newsService.GetNewsById(newsComment.NewsItemId).Title;
                    }
                    commentModel.CustomerInfo = _customerService.GetCustomerById(newsComment.Id).Email;
                    commentModel.CommentText  = HtmlHelper.FormatText(newsComment.CommentText, false, true, false, false,
                                                                      false,
                                                                      false);

                    return(commentModel);
                }).ToList(),
                Total = comments.Count
            };

            return(model);
        }
Пример #5
0
        public virtual ActionResult Comments(int?filterByNewsItemId, DataSourceRequest command, NewsCommentListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageNews))
            {
                return(AccessDeniedKendoGridJson());
            }

            var createdOnFromValue = model.CreatedOnFrom == null ? null
                           : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnFrom.Value, _dateTimeHelper.CurrentTimeZone);

            var createdOnToValue = model.CreatedOnTo == null ? null
                            : (DateTime?)_dateTimeHelper.ConvertToUtcTime(model.CreatedOnTo.Value, _dateTimeHelper.CurrentTimeZone).AddDays(1);

            bool?approved = null;

            if (model.SearchApprovedId > 0)
            {
                approved = model.SearchApprovedId == 1;
            }

            var comments = _newsService.GetAllComments(0, 0, filterByNewsItemId, approved, createdOnFromValue, createdOnToValue, model.SearchText);

            var storeNames = _storeService.GetAllStores().ToDictionary(store => store.Id, store => store.Name);

            var gridModel = new DataSourceResult
            {
                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;
                    var customer = newsComment.Customer;
                    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);
                    commentModel.IsApproved   = newsComment.IsApproved;
                    commentModel.StoreId      = newsComment.StoreId;
                    commentModel.StoreName    = storeNames.ContainsKey(newsComment.StoreId) ? storeNames[newsComment.StoreId] : "Deleted";

                    return(commentModel);
                }),
                Total = comments.Count,
            };

            return(Json(gridModel));
        }