Exemple #1
0
        /// <summary>
        /// Prepare blog comment model
        /// </summary>
        /// <param name="blogComment">Blog comment entity</param>
        /// <returns>Blog comment model</returns>
        public virtual BlogCommentModel PrepareBlogPostCommentModel(BlogComment blogComment)
        {
            if (blogComment == null)
            {
                throw new ArgumentNullException("blogComment");
            }

            var model = new BlogCommentModel
            {
                Id          = blogComment.Id,
                VisitorId   = blogComment.VisitorId,
                VisitorName = (blogComment.Visitor == null) ? string.Empty :
                              blogComment.Visitor.FirstName + " " + blogComment.Visitor.FirstName,
                CommentText          = blogComment.CommentText,
                CreatedOn            = ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),
                AllowViewingProfiles = true
            };

            if (false)
            {
                //model.CustomerAvatarUrl = _pictureService.GetPictureUrl(
                //    blogComment.Customer.GetAttribute<int>(SystemCustomerAttributeNames.AvatarPictureId),
                //    _mediaSettings.AvatarPictureSize,
                //    _customerSettings.DefaultAvatarEnabled,
                //    defaultPictureType: PictureType.Avatar);
            }

            return(model);
        }
        /// <summary>
        /// Prepare blog comment model
        /// </summary>
        /// <param name="blogComment">Blog comment entity</param>
        /// <returns>Blog comment model</returns>
        public virtual BlogCommentModel PrepareBlogPostCommentModel(BlogComment blogComment)
        {
            if (blogComment == null)
            {
                throw new ArgumentNullException(nameof(blogComment));
            }

            var model = new BlogCommentModel
            {
                Id                   = blogComment.Id,
                CustomerId           = blogComment.CustomerId,
                CustomerName         = _customerService.FormatUserName(blogComment.Customer),
                CommentText          = blogComment.CommentText,
                CreatedOn            = _dateTimeHelper.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),
                AllowViewingProfiles = _customerSettings.AllowViewingProfiles && blogComment.Customer != null && !blogComment.Customer.IsGuest()
            };

            if (_customerSettings.AllowCustomersToUploadAvatars)
            {
                model.CustomerAvatarUrl = _pictureService.GetPictureUrl(
                    _genericAttributeService.GetAttribute <int>(blogComment.Customer, GSCustomerDefaults.AvatarPictureIdAttribute),
                    _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType: PictureType.Avatar);
            }

            return(model);
        }
Exemple #3
0
        public virtual (IEnumerable <BlogCommentModel> blogComments, int totalCount) PrepareBlogPostCommentsModel(string filterByBlogPostId, int pageIndex, int pageSize)
        {
            IList <BlogComment> comments;

            if (!String.IsNullOrEmpty(filterByBlogPostId))
            {
                //filter comments by blog
                var blogPost = _blogService.GetBlogPostById(filterByBlogPostId);
                comments = _blogService.GetBlogCommentsByBlogPostId(blogPost.Id);
            }
            else
            {
                //load all blog comments
                comments = _blogService.GetAllComments("");
            }

            return(comments.Skip((pageIndex - 1) * pageSize).Take(pageSize).Select(blogComment =>
            {
                var commentModel = new BlogCommentModel();
                commentModel.Id = blogComment.Id;
                commentModel.BlogPostId = blogComment.BlogPostId;
                commentModel.BlogPostTitle = blogComment.BlogPostTitle;
                commentModel.CustomerId = blogComment.CustomerId;
                var customer = _customerService.GetCustomerById(blogComment.CustomerId);
                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;
            }), comments.Count);
        }
        public virtual ActionResult CommentUpdate(BlogCommentModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            var comment = _blogService.GetBlogCommentById(model.Id);

            if (comment == null)
            {
                throw new ArgumentException("No comment found with the specified id");
            }

            var previousIsApproved = comment.IsApproved;

            comment.IsApproved = model.IsApproved;
            _blogService.UpdateBlogPost(comment.BlogPost);

            //raise event (only if it wasn't approved before and is approved now)
            if (!previousIsApproved && comment.IsApproved)
            {
                _eventPublisher.Publish(new BlogCommentApprovedEvent(comment));
            }

            //activity log
            _customerActivityService.InsertActivity("EditBlogComment", _localizationService.GetResource("ActivityLog.EditBlogComment"), model.Id);

            return(new NullJsonResult());
        }
Exemple #5
0
        /// <summary>
        /// Prepare blog comment model
        /// </summary>
        /// <param name="blogComment">Blog comment entity</param>
        /// <returns>Blog comment model</returns>
        protected virtual async Task <BlogCommentModel> PrepareBlogPostCommentModelAsync(BlogComment blogComment)
        {
            if (blogComment == null)
            {
                throw new ArgumentNullException(nameof(blogComment));
            }

            var customer = await _customerService.GetCustomerByIdAsync(blogComment.CustomerId);

            var model = new BlogCommentModel
            {
                Id                   = blogComment.Id,
                CustomerId           = blogComment.CustomerId,
                CustomerName         = await _customerService.FormatUsernameAsync(customer),
                CommentText          = blogComment.CommentText,
                CreatedOn            = await _dateTimeHelper.ConvertToUserTimeAsync(blogComment.CreatedOnUtc, DateTimeKind.Utc),
                AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !await _customerService.IsGuestAsync(customer)
            };

            if (_customerSettings.AllowCustomersToUploadAvatars)
            {
                model.CustomerAvatarUrl = await _pictureService.GetPictureUrlAsync(
                    await _genericAttributeService.GetAttributeAsync <int>(customer, NopCustomerDefaults.AvatarPictureIdAttribute),
                    _mediaSettings.AvatarPictureSize, _customerSettings.DefaultAvatarEnabled, defaultPictureType : PictureType.Avatar);
            }

            return(model);
        }
        public async Task <BlogCommentModel> PrepareBlogPostCommentModel(BlogComment blogComment)
        {
            var customer = await _serviceProvider.GetRequiredService <ICustomerService>().GetCustomerById(blogComment.CustomerId);

            var model = new BlogCommentModel
            {
                Id                   = blogComment.Id,
                CustomerId           = blogComment.CustomerId,
                CustomerName         = customer.FormatUserName(_customerSettings.CustomerNameFormat),
                CommentText          = blogComment.CommentText,
                CreatedOn            = _dateTimeHelper.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),
                AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !customer.IsGuest(),
            };

            if (_customerSettings.AllowCustomersToUploadAvatars)
            {
                model.CustomerAvatarUrl = await _pictureService.GetPictureUrl(
                    customer.GetAttributeFromEntity <string>(SystemCustomerAttributeNames.AvatarPictureId),
                    _mediaSettings.AvatarPictureSize,
                    _customerSettings.DefaultAvatarEnabled,
                    defaultPictureType : PictureType.Avatar);
            }

            return(model);
        }
Exemple #7
0
        public BlogCommentModel PrepareBlogPostCommentModel(BlogComment blogComment)
        {
            var customer = EngineContextExperimental.Current.Resolve <ICustomerService>().GetCustomerById(blogComment.CustomerId);
            var model    = new BlogCommentModel
            {
                Id                   = blogComment.Id,
                CustomerId           = blogComment.CustomerId,
                CustomerName         = customer.FormatUserName(),
                CommentText          = blogComment.CommentText,
                CreatedOn            = _dateTimeHelper.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),
                AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !customer.IsGuest(),
            };

            if (_customerSettings.AllowCustomersToUploadAvatars)
            {
                model.CustomerAvatarUrl = _pictureService.GetPictureUrl(
                    customer.GetAttribute <string>(SystemCustomerAttributeNames.AvatarPictureId),
                    false,
                    _mediaSettings.AvatarPictureSize,
                    _customerSettings.DefaultAvatarEnabled,
                    defaultPictureType: PictureType.Avatar);
            }

            return(model);
        }
Exemple #8
0
        public ActionResult Comments(int?filterByBlogPostId, DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            IList <BlogComment> comments = filterByBlogPostId.HasValue ?
                                           //filter comments by blog
                                           _blogService.GetBlogPostById(filterByBlogPostId.Value).BlogComments.OrderBy(bc => bc.CreatedOnUtc).ToList() :
                                           //load all blog 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));
        }
Exemple #9
0
        public virtual IActionResult CommentUpdate(BlogCommentModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            //try to get a blog comment with the specified id
            var comment = _blogService.GetBlogCommentById(model.Id)
                          ?? throw new ArgumentException("No comment found with the specified id");

            var previousIsApproved = comment.IsApproved;

            //fill entity from model
            comment = model.ToEntity(comment);

            //raise event (only if it wasn't approved before and is approved now)
            if (!previousIsApproved && comment.IsApproved)
            {
                _eventPublisher.Publish(new BlogCommentApprovedEvent(comment));
            }

            //activity log
            _customerActivityService.InsertActivity("EditBlogComment",
                                                    string.Format(_localizationService.GetResource("ActivityLog.EditBlogComment"), comment.Id), comment);

            return(new NullJsonResult());
        }
Exemple #10
0
        public ActionResult Comments(int?filterByBlogPostId, GridCommand command)
        {
            var model = new GridModel <BlogCommentModel>();

            if (_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                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);
                }

                model.Data = comments.PagedForCommand(command).Select(blogComment =>
                {
                    var commentModel = new BlogCommentModel();
                    var customer     = _customerService.GetCustomerById(blogComment.CustomerId);

                    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.HtmlUtils.FormatText(blogComment.CommentText, false, true, false, false, false, false);

                    if (customer == null)
                    {
                        commentModel.CustomerName = "".NaIfEmpty();
                    }
                    else
                    {
                        commentModel.CustomerName = customer.GetFullName();
                    }

                    return(commentModel);
                });

                model.Total = comments.Count;
            }
            else
            {
                model.Data = Enumerable.Empty <BlogCommentModel>();

                NotifyAccessDenied();
            }

            return(new JsonResult
            {
                Data = model
            });
        }
        public static async Task <bool> SubmitComment(BlogCommentModel comment)
        {
            if (comment.Subscribe)
            {
                await AddSubscriber(comment.Email);
            }

            return(await JsnoRepo.SubmitComment(BlogCommentModel.MapToDto(comment)));
        }
Exemple #12
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);
        }
Exemple #13
0
        protected void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments)
        {
            if (blogPost == null)
            {
                throw new ArgumentNullException("blogPost");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.Id                            = blogPost.Id;
            model.MetaTitle                     = blogPost.MetaTitle;
            model.MetaDescription               = blogPost.MetaDescription;
            model.MetaKeywords                  = blogPost.MetaKeywords;
            model.SeName                        = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false);
            model.Title                         = blogPost.Title;
            model.Body                          = blogPost.Body;
            model.AllowComments                 = blogPost.AllowComments;
            model.AvatarPictureSize             = _mediaSettings.AvatarPictureSize; // codehint: sm-add
            model.CreatedOn                     = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc);
            model.Tags                          = blogPost.ParseTags().ToList();
            model.NumberOfComments              = blogPost.ApprovedCommentCount;
            model.AddNewComment.DisplayCaptcha  = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage;
            model.AllowCustomersToUploadAvatars = _customerSettings.AllowCustomersToUploadAvatars;
            if (prepareComments)
            {
                var blogComments = blogPost.BlogComments.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc);
                foreach (var bc in blogComments)
                {
                    var commentModel = new BlogCommentModel()
                    {
                        Id                   = bc.Id,
                        CustomerId           = bc.CustomerId,
                        CustomerName         = bc.Customer.FormatUserName(),
                        CommentText          = bc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && bc.Customer != null && !bc.Customer.IsGuest()
                    };
                    if (_customerSettings.AllowCustomersToUploadAvatars)
                    {
                        var    customer  = bc.Customer;
                        string avatarUrl = _pictureService.GetPictureUrl(customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false);
                        if (String.IsNullOrEmpty(avatarUrl) && _customerSettings.DefaultAvatarEnabled)
                        {
                            avatarUrl = _pictureService.GetDefaultPictureUrl(_mediaSettings.AvatarPictureSize, PictureType.Avatar);
                        }
                        commentModel.CustomerAvatarUrl = avatarUrl;
                    }
                    model.Comments.Add(commentModel);
                }
            }
        }
Exemple #14
0
        protected virtual void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments)
        {
            if (blogPost == null)
            {
                throw new ArgumentNullException("blogPost");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.Id                           = blogPost.Id;
            model.MetaTitle                    = blogPost.MetaTitle;
            model.MetaDescription              = blogPost.MetaDescription;
            model.MetaKeywords                 = blogPost.MetaKeywords;
            model.SeName                       = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false);
            model.Title                        = blogPost.Title;
            model.Body                         = blogPost.Body;
            model.BodyOverview                 = blogPost.BodyOverview;
            model.AllowComments                = blogPost.AllowComments;
            model.CreatedOn                    = _dateTimeHelper.ConvertToUserTime(blogPost.StartDateUtc ?? blogPost.CreatedOnUtc, DateTimeKind.Utc);
            model.Tags                         = blogPost.ParseTags().ToList();
            model.NumberOfComments             = blogPost.CommentCount;
            model.AddNewComment.DisplayCaptcha = _captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage;
            if (prepareComments)
            {
                var blogComments = _blogService.GetBlogCommentsByBlogPostId(blogPost.Id);
                foreach (var bc in blogComments)
                {
                    var customer     = EngineContext.Current.Resolve <ICustomerService>().GetCustomerById(bc.CustomerId);
                    var commentModel = new BlogCommentModel
                    {
                        Id                   = bc.Id,
                        CustomerId           = bc.CustomerId,
                        CustomerName         = customer.FormatUserName(),
                        CommentText          = bc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !customer.IsGuest(),
                    };
                    if (_customerSettings.AllowCustomersToUploadAvatars)
                    {
                        commentModel.CustomerAvatarUrl = _pictureService.GetPictureUrl(
                            customer.GetAttribute <string>(SystemCustomerAttributeNames.AvatarPictureId),
                            _mediaSettings.AvatarPictureSize,
                            _customerSettings.DefaultAvatarEnabled,
                            defaultPictureType: PictureType.Avatar);
                    }
                    model.Comments.Add(commentModel);
                }
            }
        }
Exemple #15
0
        public ActionResult Comments(int?filterByBlogPostId, GridCommand command)
        {
            var model = new GridModel <BlogCommentModel>();

            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);
            }

            model.Data = comments.PagedForCommand(command).Select(blogComment =>
            {
                var commentModel = new BlogCommentModel();
                var customer     = _customerService.GetCustomerById(blogComment.CustomerId);

                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       = HtmlUtils.ConvertPlainTextToHtml(blogComment.CommentText.HtmlEncode());

                if (customer == null)
                {
                    commentModel.CustomerName = "".NaIfEmpty();
                }
                else
                {
                    commentModel.CustomerName = customer.GetFullName();
                }

                return(commentModel);
            });

            model.Total = comments.Count;

            return(new JsonResult
            {
                Data = model
            });
        }
        public ActionResult Comments(int?filterByBlogPostId, GridCommand command)
        {
            IPagedList <BlogComment> comments;

            if (filterByBlogPostId.HasValue)
            {
                // Filter comments by blog.
                var query = _customerContentService.GetAllCustomerContent <BlogComment>(0, null).SourceQuery;
                query = query.Where(x => x.BlogPostId == filterByBlogPostId.Value);

                comments = new PagedList <BlogComment>(query, command.Page - 1, command.PageSize);
            }
            else
            {
                // Load all blog comments.
                comments = _customerContentService.GetAllCustomerContent <BlogComment>(0, null, null, null, command.Page - 1, command.PageSize);
            }

            var customerIds = comments.Select(x => x.CustomerId).Distinct().ToArray();
            var customers   = _customerService.GetCustomersByIds(customerIds).ToDictionarySafe(x => x.Id);

            var model = new GridModel <BlogCommentModel>
            {
                Total = comments.TotalCount
            };

            model.Data = comments.Select(blogComment =>
            {
                customers.TryGetValue(blogComment.CustomerId, out var customer);

                var commentModel = new BlogCommentModel
                {
                    Id            = blogComment.Id,
                    BlogPostId    = blogComment.BlogPostId,
                    BlogPostTitle = blogComment.BlogPost.GetLocalized(x => x.Title),
                    CustomerId    = blogComment.CustomerId,
                    IpAddress     = blogComment.IpAddress,
                    CreatedOn     = _dateTimeHelper.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),
                    Comment       = HtmlUtils.ConvertPlainTextToHtml(blogComment.CommentText.HtmlEncode()),
                    CustomerName  = customer.GetDisplayName(T)
                };

                return(commentModel);
            });

            return(new JsonResult
            {
                Data = model
            });
        }
Exemple #17
0
        public virtual IActionResult Comments(int?filterByBlogPostId, DataSourceRequest command, BlogCommentListModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                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 = _blogService.GetAllComments(0, 0, filterByBlogPostId, 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(blogComment =>
                {
                    var commentModel = new BlogCommentModel
                    {
                        Id            = blogComment.Id,
                        BlogPostId    = blogComment.BlogPostId,
                        BlogPostTitle = blogComment.BlogPost.Title,
                        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);
                    commentModel.IsApproved   = blogComment.IsApproved;
                    commentModel.StoreId      = blogComment.StoreId;
                    commentModel.StoreName    = storeNames.ContainsKey(blogComment.StoreId) ? storeNames[blogComment.StoreId] : "Deleted";

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

            return(Json(gridModel));
        }
Exemple #18
0
        private async Task <BlogCommentModel> PrepareBlogPostCommentModel(BlogComment blogComment)
        {
            var customer = await _customerService.GetCustomerById(blogComment.CustomerId);

            var model = new BlogCommentModel {
                Id                   = blogComment.Id,
                CustomerId           = blogComment.CustomerId,
                CustomerName         = customer.FormatUserName(_customerSettings.CustomerNameFormat),
                CommentText          = blogComment.CommentText,
                CreatedOn            = _dateTimeHelper.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),
                AllowViewingProfiles = _customerSettings.AllowViewingProfiles && customer != null && !customer.IsGuest(),
            };

            return(model);
        }
Exemple #19
0
        private async Task <BlogCommentModel> PrepareBlogPostCommentModel(BlogComment blogComment)
        {
            var customer = await _customerService.GetCustomerById(blogComment.CustomerId);

            var model = new BlogCommentModel
            {
                Id           = blogComment.Id,
                CustomerId   = blogComment.CustomerId,
                CustomerName = customer.FormatUserName(_customerSettings.CustomerNameFormat),
                CommentText  = blogComment.CommentText,
                CreatedOn    = _dateTimeService.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc),
            };

            return(model);
        }
Exemple #20
0
        private void PrepareBlogPostModel(BlogPostModel model, BlogPost blogPost, bool prepareComments)
        {
            if (blogPost == null)
            {
                throw new ArgumentNullException("blogPost");
            }

            if (model == null)
            {
                throw new ArgumentNullException("model");
            }

            model.Id               = blogPost.Id;
            model.SeName           = blogPost.GetSeName();
            model.Title            = blogPost.Title;
            model.Body             = blogPost.Body;
            model.AllowComments    = blogPost.AllowComments;
            model.CreatedOn        = _dateTimeHelper.ConvertToUserTime(blogPost.CreatedOnUtc, DateTimeKind.Utc);
            model.Tags             = blogPost.ParseTags().ToList();
            model.NumberOfComments = blogPost.BlogComments.Count;
            if (prepareComments)
            {
                var blogComments = blogPost.BlogComments.Where(pr => pr.IsApproved).OrderBy(pr => pr.CreatedOnUtc);
                foreach (var bc in blogComments)
                {
                    var commentModel = new BlogCommentModel()
                    {
                        Id                   = bc.Id,
                        CustomerId           = bc.CustomerId,
                        CustomerName         = bc.Customer.FormatUserName(),
                        CommentText          = bc.CommentText,
                        CreatedOn            = _dateTimeHelper.ConvertToUserTime(bc.CreatedOnUtc, DateTimeKind.Utc),
                        AllowViewingProfiles = _customerSettings.AllowViewingProfiles && bc.Customer != null && !bc.Customer.IsGuest(),
                    };
                    if (_customerSettings.AllowCustomersToUploadAvatars)
                    {
                        var    customer  = bc.Customer;
                        string avatarUrl = _pictureService.GetPictureUrl(customer.GetAttribute <int>(SystemCustomerAttributeNames.AvatarPictureId), _mediaSettings.AvatarPictureSize, false);
                        if (string.IsNullOrEmpty(avatarUrl) && _customerSettings.DefaultAvatarEnabled)
                        {
                            avatarUrl = _pictureService.GetDefaultPictureUrl(_mediaSettings.AvatarPictureSize, PictureType.Avatar);
                        }
                        commentModel.CustomerAvatarUrl = avatarUrl;
                    }
                    model.Comments.Add(commentModel);
                }
            }
        }
Exemple #21
0
        public virtual IActionResult CommentUpdate(BlogCommentModel model)
        {
            //try to get a blog comment with the specified id
            BlogComment comment = _blogService.GetBlogCommentById(model.Id)
                                  ?? throw new ArgumentException("No comment found with the specified id");

            bool previousIsApproved = comment.IsApproved;

            comment.IsApproved = model.IsApproved;
            _blogService.UpdateBlogPost(comment.BlogPost);
            //activity log
            _customerActivityService.InsertActivity("EditBlogComment",
                                                    $"EditBlogComment{comment.Id}", comment);

            return(new NullJsonResult());
        }
Exemple #22
0
        /// <summary>
        /// Adds the comment in the CommentFormViewModel to the Episerver Social repository.
        /// </summary>
        /// <param name="formViewModel">The submitted comment form view model.</param>
        /// <returns>The added PageComment</returns>
        private BlogCommentModel AddComment(BlogCommentFormViewModel formViewModel)
        {
            var newComment = AdaptCommentFormViewModelToSocialComment(formViewModel);
            BlogCommentModel addedComment = null;

            try
            {
                addedComment = _commentRepository.Add(newComment);
                AddMessage(MessageKey, SubmitSuccessMessage);
            }
            catch (Exception ex)
            {
                AddMessage(MessageKey, ex.Message);
            }

            return(addedComment);
        }
Exemple #23
0
        /// <summary>
        /// Prepare blog comment model
        /// </summary>
        /// <param name="blogComment">Blog comment entity</param>
        /// <returns>Blog comment model</returns>
        public virtual BlogCommentModel PrepareBlogPostCommentModel(BlogComment blogComment)
        {
            if (blogComment == null)
            {
                throw new ArgumentNullException(nameof(blogComment));
            }

            var model = new BlogCommentModel
            {
                Id           = blogComment.Id,
                CustomerId   = blogComment.CustomerId,
                CustomerName = blogComment.Customer.Name,
                CommentText  = blogComment.CommentText,
                CreatedOn    = blogComment.CreatedOnUtc,
            };

            return(model);
        }
Exemple #24
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);
        }
Exemple #25
0
        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
            });
        }
Exemple #26
0
        public ActionResult Comments(string filterByBlogPostId, DataSourceRequest command)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            IList <BlogComment> comments;

            if (!String.IsNullOrEmpty(filterByBlogPostId))
            {
                //filter comments by blog
                var blogPost = _blogService.GetBlogPostById(filterByBlogPostId);
                comments = _blogService.GetBlogCommentsByBlogPostId(blogPost.Id);
            }
            else
            {
                //load all blog comments
                comments = _blogService.GetAllComments("");
            }

            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.BlogPostTitle;
                    commentModel.CustomerId    = blogComment.CustomerId;
                    var customer = EngineContext.Current.Resolve <ICustomerService>().GetCustomerById(blogComment.CustomerId);
                    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));
        }
        public ActionResult CommentUpdate(BlogCommentModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManageBlog))
            {
                return(AccessDeniedView());
            }

            var comment = _blogService.GetBlogCommentById(model.Id);

            if (comment == null)
            {
                throw new ArgumentException("No comment found with the specified id");
            }

            comment.IsApproved = model.IsApproved;
            _blogService.UpdateBlogPost(comment.BlogPost);

            //activity log
            _customerActivityService.InsertActivity("EditBlogComment", _localizationService.GetResource("ActivityLog.EditBlogComment"), model.Id);

            return(new NullJsonResult());
        }
Exemple #28
0
        public IActionResult CreateNewBlogPostComment(CreateBlogPostCommentRequest createBlogPostComment)
        {
            try
            {
                var contextBlogPost = _context.BlogPosts.Find(createBlogPostComment?.BlogPost?.ID);

                if (contextBlogPost == null || string.IsNullOrEmpty(createBlogPostComment?.Comment))
                {
                    throw new Exception("Cannot add comment to the blog as the request is invaid.");
                }

                var newComment = new BlogCommentModel
                {
                    ID         = Guid.NewGuid(),
                    BlogPost   = contextBlogPost,
                    Comment    = createBlogPostComment.Comment,
                    IsApproved = true,
                    UserId     = Guid.Parse("A37110A0-12D5-4AB6-89A0-504A335F64E4")
                };

                _context.Add(newComment);
                _context.SaveChanges();

                return(Ok(JsonSerializer.Serialize(newComment)));
            }
            catch (Exception ex)
            {
                _logger.LogError($"An unexpected error occurred retrieving all blog posts for the current user, {ex.Message}{Environment.NewLine}{ex.StackTrace}");
                var i = 0; // Added i to prevent the while loop to accidentally be looping indefinitely.
                while (ex.InnerException != null && i < 10)
                {
                    _logger.LogError(ex.InnerException.StackTrace);
                    ex = ex.InnerException;
                    i++;
                }

                throw new Exception("An unexpected error occurred trying to create the blog post for the current user");
            }
        }
Exemple #29
0
        public virtual async Task <(IEnumerable <BlogCommentModel> blogComments, int totalCount)> PrepareBlogPostCommentsModel(string filterByBlogPostId, int pageIndex, int pageSize)
        {
            IList <BlogComment> comments;
            var storeId = string.IsNullOrEmpty(_workContext.CurrentCustomer.StaffStoreId) ? "" : _workContext.CurrentCustomer.StaffStoreId;

            if (!string.IsNullOrEmpty(filterByBlogPostId))
            {
                //filter comments by blog
                var blogPost = await _blogService.GetBlogPostById(filterByBlogPostId);

                comments = await _blogService.GetBlogCommentsByBlogPostId(blogPost.Id);
            }
            else
            {
                //load all blog comments
                comments = await _blogService.GetAllComments("", storeId);
            }
            var commentsList = new List <BlogCommentModel>();

            foreach (var blogComment in comments.Skip((pageIndex - 1) * pageSize).Take(pageSize))
            {
                var commentModel = new BlogCommentModel
                {
                    Id            = blogComment.Id,
                    BlogPostId    = blogComment.BlogPostId,
                    BlogPostTitle = blogComment.BlogPostTitle,
                    CustomerId    = blogComment.CustomerId
                };
                var customer = await _customerService.GetCustomerById(blogComment.CustomerId);

                commentModel.CustomerInfo = !string.IsNullOrEmpty(customer.Email) ? customer.Email : _translationService.GetResource("Admin.Customers.Guest");
                commentModel.CreatedOn    = _dateTimeService.ConvertToUserTime(blogComment.CreatedOnUtc, DateTimeKind.Utc);
                commentModel.Comment      = FormatText.ConvertText(blogComment.CommentText);
                commentsList.Add(commentModel);
            }
            return(commentsList, comments.Count);
        }
Exemple #30
0
 public BlogCommentModel Add(BlogCommentModel comment)
 {
     return(new BlogCommentModel());
 }