Пример #1
0
 public LiquidKnowledgebase(KnowledgebaseArticle article, KnowledgebaseArticleComment articleComment, Store store, Language language)
 {
     _article         = article;
     _articleComment  = articleComment;
     _store           = store;
     _language        = language;
     AdditionalTokens = new Dictionary <string, string>();
 }
        public LiquidKnowledgebase(KnowledgebaseArticleComment articleComment, string storeId)
        {
            this._storeService   = EngineContext.Current.Resolve <IStoreService>();
            this._articleComment = articleComment;
            this._storeId        = storeId;

            AdditionalTokens = new Dictionary <string, string>();
        }
Пример #3
0
        public virtual async Task DeleteArticleComment(KnowledgebaseArticleComment articleComment)
        {
            if (articleComment == null)
            {
                throw new ArgumentNullException("articleComment");
            }

            await _articleCommentRepository.DeleteAsync(articleComment);
        }
Пример #4
0
        public void DeleteArticleComment(KnowledgebaseArticleComment articleComment)
        {
            if (articleComment == null)
            {
                throw new ArgumentNullException("articleComment");
            }

            _articleCommentRepository.Delete(articleComment);
        }
Пример #5
0
        /// <summary>
        /// Inserts an article comment
        /// </summary>
        /// <param name="articleComment">Article comment</param>
        public virtual async Task InsertArticleComment(KnowledgebaseArticleComment articleComment)
        {
            if (articleComment == null)
            {
                throw new ArgumentNullException("articleComment");
            }

            await _articleCommentRepository.InsertAsync(articleComment);

            //event notification
            await _mediator.EntityInserted(articleComment);
        }
Пример #6
0
        /// <summary>
        /// Inserts an article comment
        /// </summary>
        /// <param name="articleComment">Article comment</param>
        public void InsertArticleComment(KnowledgebaseArticleComment articleComment)
        {
            if (articleComment == null)
            {
                throw new ArgumentNullException("articleComment");
            }

            _articleCommentRepository.Insert(articleComment);

            //event notification
            _eventPublisher.EntityInserted(articleComment);
        }
        public async Task AddArticleCommentTokens(LiquidObject liquidObject, KnowledgebaseArticle article, KnowledgebaseArticleComment articleComment, Store store, Language language)
        {
            var liquidKnowledgebase = new LiquidKnowledgebase(article, articleComment, store, language);

            liquidObject.Knowledgebase = liquidKnowledgebase;
            await _mediator.EntityTokensAdded(articleComment, liquidKnowledgebase, liquidObject);
        }
        public virtual async Task <IActionResult> ArticleCommentAdd(string articleId, KnowledgebaseArticleModel model, bool captchaValid,
                                                                    [FromServices] IWorkContext workContext, [FromServices] ICustomerService customerService)
        {
            if (!_knowledgebaseSettings.Enabled)
            {
                return(RedirectToRoute("HomePage"));
            }

            var article = await _knowledgebaseService.GetPublicKnowledgebaseArticle(articleId);

            if (article == null || !article.AllowComments)
            {
                return(RedirectToRoute("HomePage"));
            }

            if (workContext.CurrentCustomer.IsGuest() && !_knowledgebaseSettings.AllowNotRegisteredUsersToLeaveComments)
            {
                ModelState.AddModelError("", _localizationService.GetResource("Knowledgebase.Article.Comments.OnlyRegisteredUsersLeaveComments"));
            }

            //validate CAPTCHA
            if (_captchaSettings.Enabled && _captchaSettings.ShowOnArticleCommentPage && !captchaValid)
            {
                ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService));
            }

            if (ModelState.IsValid)
            {
                var customer = _workContext.CurrentCustomer;
                var comment  = new KnowledgebaseArticleComment {
                    ArticleId    = article.Id,
                    CustomerId   = customer.Id,
                    CommentText  = model.AddNewComment.CommentText,
                    CreatedOnUtc = DateTime.UtcNow,
                    ArticleTitle = article.Name,
                };
                await _knowledgebaseService.InsertArticleComment(comment);

                if (!customer.HasContributions)
                {
                    await customerService.UpdateContributions(customer);
                }

                //notify a store owner
                if (_knowledgebaseSettings.NotifyAboutNewArticleComments)
                {
                    await _workflowMessageService.SendArticleCommentNotificationMessage(article, comment, _localizationSettings.DefaultAdminLanguageId);
                }

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

                //The text boxes should be cleared after a comment has been posted
                //That' why we reload the page
                TempData["Grand.knowledgebase.addarticlecomment.result"] = _localizationService.GetResource("Knowledgebase.Article.Comments.SuccessfullyAdded");
                return(RedirectToRoute("KnowledgebaseArticle", new { SeName = article.GetSeName(_workContext.WorkingLanguage.Id) }));
            }

            //If we got this far, something failed, redisplay form
            await PrepareKnowledgebaseArticleModel(model, article, customerService);

            return(View("Article", model));
        }
Пример #9
0
 public LiquidObjectBuilder AddArticleCommentTokens(KnowledgebaseArticle article, KnowledgebaseArticleComment articleComment, Store store, Language language)
 {
     _chain.Add(async liquidObject =>
     {
         var liquidKnowledgebase    = new LiquidKnowledgebase(article, articleComment, store, language);
         liquidObject.Knowledgebase = liquidKnowledgebase;
         await _mediator.EntityTokensAdded(articleComment, liquidKnowledgebase, liquidObject);
     });
     return(this);
 }
Пример #10
0
        public void AddArticleCommentTokens(string storeId, LiquidObject liquidObject, KnowledgebaseArticleComment articleComment)
        {
            var liquidKnowledgebase = new LiquidKnowledgebase(articleComment, storeId);

            liquidObject.Knowledgebase = liquidKnowledgebase;

            _eventPublisher.EntityTokensAdded(articleComment, liquidKnowledgebase, liquidObject);
        }