Exemple #1
0
        public async Task <BlogComment> Handle(InsertBlogCommentCommand request, CancellationToken cancellationToken)
        {
            var customer = _workContext.CurrentCustomer;
            var comment  = new BlogComment
            {
                BlogPostId    = request.BlogPost.Id,
                CustomerId    = customer.Id,
                StoreId       = _workContext.CurrentStore.Id,
                CommentText   = request.Model.AddNewComment.CommentText,
                CreatedOnUtc  = DateTime.UtcNow,
                BlogPostTitle = request.BlogPost.Title,
            };
            await _blogService.InsertBlogComment(comment);

            //update totals
            var comments = await _blogService.GetBlogCommentsByBlogPostId(request.BlogPost.Id);

            request.BlogPost.CommentCount = comments.Count;
            await _blogService.UpdateBlogPost(request.BlogPost);

            if (!customer.HasContributions)
            {
                await _customerService.UpdateContributions(customer);
            }
            //notify a store owner
            if (_blogSettings.NotifyAboutNewBlogComments)
            {
                await _messageProviderService.SendBlogCommentMessage(request.BlogPost, comment, _languageSettings.DefaultAdminLanguageId);
            }

            //activity log
            await _customerActivityService.InsertActivity("PublicStore.AddBlogComment", comment.Id, _translationService.GetResource("ActivityLog.PublicStore.AddBlogComment"));

            return(comment);
        }