示例#1
0
        /// <summary>
        /// Prepare blog comment search model
        /// </summary>
        /// <param name="searchModel">Blog comment search model</param>
        /// <param name="blogPost">Blog post</param>
        /// <returns>Blog comment search model</returns>
        public virtual BlogCommentSearchModel PrepareBlogCommentSearchModel(BlogCommentSearchModel searchModel, BlogPost blogPost)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

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

            searchModel.BlogPostId = blogPost?.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
示例#2
0
        public virtual IActionResult Comments(BlogCommentSearchModel searchModel)
        {
            //prepare model
            BlogCommentListModel model = _blogModelFactory.PrepareBlogCommentListModel(searchModel, searchModel.BlogPostId);

            return(Json(model));
        }
示例#3
0
        /// <summary>
        /// Prepare blog comment search model
        /// </summary>
        /// <param name="searchModel">Blog comment search model</param>
        /// <param name="blogPost">Blog post</param>
        /// <returns>Blog comment search model</returns>
        public virtual BlogCommentSearchModel PrepareBlogCommentSearchModel(BlogCommentSearchModel searchModel, BlogPost blogPost)
        {
            if (searchModel == null)
            {
                throw new ArgumentNullException(nameof(searchModel));
            }

            //prepare "approved" property (0 - all; 1 - approved only; 2 - disapproved only)
            searchModel.AvailableApprovedOptions.Add(new SelectListItem
            {
                Text  = "Hepsi",
                Value = "0"
            });
            searchModel.AvailableApprovedOptions.Add(new SelectListItem
            {
                Text  = "Onaylı",
                Value = "1"
            });
            searchModel.AvailableApprovedOptions.Add(new SelectListItem
            {
                Text  = "Onaysız",
                Value = "2"
            });

            searchModel.BlogPostId = blogPost?.Id;

            //prepare page parameters
            searchModel.SetGridPageSize();

            return(searchModel);
        }
示例#4
0
        /// <summary>
        /// Prepare paged blog comment list model
        /// </summary>
        /// <param name="searchModel">Blog comment search model</param>
        /// <param name="blogPost">Blog post; pass null to prepare comment models for all blog posts</param>
        /// <returns>Blog comment list model</returns>
        public virtual BlogCommentListModel PrepareBlogCommentListModel(BlogCommentSearchModel searchModel, BlogPost blogPost)
        {
            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 = _blogService.GetAllComments(blogPostId: blogPost?.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 BlogCommentListModel
            {
                Data = comments.PaginationByRequestModel(searchModel).Select(blogComment =>
                {
                    //fill in model values from the entity
                    var commentModel = new BlogCommentModel
                    {
                        Id            = blogComment.Id,
                        BlogPostId    = blogComment.BlogPostId,
                        BlogPostTitle = blogComment.BlogPost.Title,
                        CustomerId    = blogComment.CustomerId,
                        IsApproved    = blogComment.IsApproved,
                        StoreId       = blogComment.StoreId
                    };

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

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

            return(model);
        }
示例#5
0
        public virtual IActionResult Comments(BlogCommentSearchModel searchModel)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedDataTablesJson());
            }

            //prepare model
            var model = _blogModelFactory.PrepareBlogCommentListModel(searchModel, searchModel.BlogPostId);

            return(Json(model));
        }
示例#6
0
        public virtual IActionResult Comments(int?filterByBlogPostId)
        {
            //try to get a blog post with the specified id
            BlogPost blogPost = _blogService.GetBlogPostById(filterByBlogPostId ?? 0);

            if (blogPost == null && filterByBlogPostId.HasValue)
            {
                return(RedirectToAction("List"));
            }

            //prepare model
            BlogCommentSearchModel model = _blogModelFactory.PrepareBlogCommentSearchModel(new BlogCommentSearchModel(), blogPost);

            return(View(model));
        }
示例#7
0
        /// <summary>
        /// Prepare paged blog comment list model
        /// </summary>
        /// <param name="searchModel">Blog comment search model</param>
        /// <param name="blogPostId">Blog post ID</param>
        /// <returns>Blog comment list model</returns>
        public virtual BlogCommentListModel PrepareBlogCommentListModel(BlogCommentSearchModel searchModel, int?blogPostId)
        {
            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 = _blogService.GetAllComments(blogPostId: blogPostId,
                                                       approved: isApprovedOnly,
                                                       fromUtc: createdOnFromValue,
                                                       toUtc: createdOnToValue,
                                                       commentText: searchModel.SearchText).ToPagedList(searchModel);

            //prepare list model
            var model = new BlogCommentListModel().PrepareToGrid(searchModel, comments, () =>
            {
                //prepare store names (to avoid loading for each comment)
                var storeNames = _storeService.GetAllStores().ToDictionary(store => store.Id, store => store.Name);

                return(comments.Select(blogComment =>
                {
                    //fill in model values from the entity
                    var commentModel = blogComment.ToModel <BlogCommentModel>();

                    //set title from linked blog post
                    commentModel.BlogPostTitle = _blogService.GetBlogPostById(blogComment.BlogPostId)?.Title;

                    if (_customerService.GetCustomerById(blogComment.CustomerId) is Customer customer)
                    {
                        commentModel.CustomerInfo = _customerService.IsRegistered(customer) ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest");
                    }

                    //fill in additional values (not existing in the entity)
                    commentModel.CreatedOn = _dateTimeHelper.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc);
                    commentModel.Comment = HtmlHelper.FormatText(blogComment.CommentText, false, true, false, false, false, false);
                    commentModel.StoreName = storeNames.ContainsKey(blogComment.StoreId) ? storeNames[blogComment.StoreId] : "Deleted";

                    return commentModel;
                }));
            });
示例#8
0
        /// <summary>
        /// Prepare paged blog comment list model
        /// </summary>
        /// <param name="searchModel">Blog comment search model</param>
        /// <param name="blogPostId">Blog post ID</param>
        /// <returns>Blog comment list model</returns>
        public virtual BlogCommentListModel PrepareBlogCommentListModel(BlogCommentSearchModel searchModel, int?blogPostId)
        {
            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
            System.Collections.Generic.IList <BlogComment> comments = _blogService.GetAllComments(blogPostId: blogPostId,
                                                                                                  approved: isApprovedOnly,
                                                                                                  fromUtc: createdOnFromValue,
                                                                                                  toUtc: createdOnToValue,
                                                                                                  commentText: searchModel.SearchText);

            //prepare store names (to avoid loading for each comment)
            System.Collections.Generic.Dictionary <int, string> storeNames = _storeService.GetAllStores().ToDictionary(store => store.Id, store => store.Name);

            //prepare list model
            BlogCommentListModel model = new BlogCommentListModel
            {
                Data = comments.PaginationByRequestModel(searchModel).Select(blogComment =>
                {
                    //fill in model values from the entity
                    BlogCommentModel commentModel = blogComment.ToModel <BlogCommentModel>();

                    //fill in additional values (not existing in the entity)
                    commentModel.CustomerInfo = blogComment.Customer.Email;
                    commentModel.CreatedOn    = blogComment.CreatedOnUtc;
                    commentModel.Comment      = HtmlHelper.FormatText(blogComment.CommentText, false, true, false, false, false, false);

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

            return(model);
        }
示例#9
0
        public virtual IActionResult Comments(BlogCommentSearchModel searchModel, int?filterByBlogPostId)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedKendoGridJson());
            }

            //try to get a blog post with the specified id
            var blogPost = _blogService.GetBlogPostById(filterByBlogPostId ?? 0);

            if (blogPost == null && filterByBlogPostId.HasValue)
            {
                throw new ArgumentException("No blog post found with the specified id", nameof(filterByBlogPostId));
            }

            //prepare model
            var model = _blogModelFactory.PrepareBlogCommentListModel(searchModel, blogPost);

            return(Json(model));
        }