/// <summary> /// Sends a news comment notification message to a store owner /// </summary> /// <param name="newsComment">News comment</param> /// <param name="languageId">Message language identifier</param> /// <returns>Queued email identifier</returns> public virtual int SendNewsCommentNotificationMessage(NewsComment newsComment, int languageId) { if (newsComment == null) throw new ArgumentNullException("newsComment"); var store = _storeContext.CurrentStore; languageId = EnsureLanguageIsActive(languageId, store.Id); var messageTemplate = GetLocalizedActiveMessageTemplate("News.NewsComment", languageId, store.Id); if (messageTemplate == null) return 0; //tokens var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens, store); _messageTokenProvider.AddNewsCommentTokens(tokens, newsComment); //event notification _eventPublisher.MessageTokensAdded(messageTemplate, tokens); var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); var toEmail = emailAccount.Email; var toName = emailAccount.DisplayName; // use customer email as sender/reply address var replyTo = GetReplyToEmail(newsComment.Customer); return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName, replyTo.Item1, replyTo.Item2); }
public virtual void AddNewsCommentTokens(IList<Token> tokens, NewsComment newsComment) { tokens.Add(new Token("NewsComment.NewsTitle", newsComment.NewsItem.Title)); //event notification _eventPublisher.EntityTokensAdded(newsComment, tokens); }
public ActionResult NewsCommentAdd(int newsItemId, NewsItemModel model, bool captchaValid) { if (!_newsSettings.Enabled) return HttpNotFound(); var newsItem = _newsService.GetNewsById(newsItemId); if (newsItem == null || !newsItem.Published || !newsItem.AllowComments) return HttpNotFound(); //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnNewsCommentPage && !captchaValid) { ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha")); } if (_workContext.CurrentCustomer.IsGuest() && !_newsSettings.AllowNotRegisteredUsersToLeaveComments) { ModelState.AddModelError("", _localizationService.GetResource("News.Comments.OnlyRegisteredUsersLeaveComments")); } if (ModelState.IsValid) { var comment = new NewsComment() { NewsItemId = newsItem.Id, CustomerId = _workContext.CurrentCustomer.Id, IpAddress = _webHelper.GetCurrentIpAddress(), CommentTitle = model.AddNewComment.CommentTitle, CommentText = model.AddNewComment.CommentText, IsApproved = true, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow, }; _customerContentService.InsertCustomerContent(comment); //update totals _newsService.UpdateCommentTotals(newsItem); //notify a store owner; if (_newsSettings.NotifyAboutNewNewsComments) _workflowMessageService.SendNewsCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId); //activity log _customerActivityService.InsertActivity("PublicStore.AddNewsComment", _localizationService.GetResource("ActivityLog.PublicStore.AddNewsComment")); NotifySuccess(T("News.Comments.SuccessfullyAdded")); return RedirectToRoute("NewsItem", new { SeName = newsItem.GetSeName(newsItem.LanguageId, ensureTwoPublishedLanguages: false) }); } //If we got this far, something failed, redisplay form PrepareNewsItemModel(model, newsItem, true); return View(model); }