public virtual void AddBlogCommentTokens(IList<Token> tokens, BlogComment blogComment) { tokens.Add(new Token("BlogComment.BlogPostTitle", blogComment.BlogPost.Title)); //event notification _eventPublisher.EntityTokensAdded(blogComment, tokens); }
public ActionResult BlogCommentAdd(int blogPostId, BlogPostModel model, bool captchaValid) { if (!_blogSettings.Enabled) return HttpNotFound(); var blogPost = _blogService.GetBlogPostById(blogPostId); if (blogPost == null || !blogPost.AllowComments) return HttpNotFound(); if (_workContext.CurrentCustomer.IsGuest() && !_blogSettings.AllowNotRegisteredUsersToLeaveComments) { ModelState.AddModelError("", _localizationService.GetResource("Blog.Comments.OnlyRegisteredUsersLeaveComments")); } //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnBlogCommentPage && !captchaValid) { ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha")); } if (ModelState.IsValid) { var comment = new BlogComment() { BlogPostId = blogPost.Id, CustomerId = _workContext.CurrentCustomer.Id, IpAddress = _webHelper.GetCurrentIpAddress(), CommentText = model.AddNewComment.CommentText, IsApproved = true, CreatedOnUtc = DateTime.UtcNow, UpdatedOnUtc = DateTime.UtcNow, }; _customerContentService.InsertCustomerContent(comment); //update totals _blogService.UpdateCommentTotals(blogPost); //notify a store owner if (_blogSettings.NotifyAboutNewBlogComments) _workflowMessageService.SendBlogCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId); //activity log _customerActivityService.InsertActivity("PublicStore.AddBlogComment", _localizationService.GetResource("ActivityLog.PublicStore.AddBlogComment")); //The text boxes should be cleared after a comment has been posted //That' why we reload the page TempData["sm.blog.addcomment.result"] = _localizationService.GetResource("Blog.Comments.SuccessfullyAdded"); // codehint: sm-add (MC) > append url fragment to route url string url = UrlHelper.GenerateUrl( routeName: "BlogPost", actionName: null, controllerName: null, protocol: null, hostName: null, fragment: "new-comment", routeValues: new RouteValueDictionary(new { blogPostId = blogPost.Id, SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false) }), routeCollection: System.Web.Routing.RouteTable.Routes, requestContext: this.ControllerContext.RequestContext, includeImplicitMvcValues: true /*helps fill in the nulls above*/ ); return Redirect(url); } //If we got this far, something failed, redisplay form PrepareBlogPostModel(model, blogPost, true); return View(model); }
/// <summary> /// Sends a blog comment notification message to a store owner /// </summary> /// <param name="blogComment">Blog comment</param> /// <param name="languageId">Message language identifier</param> /// <returns>Queued email identifier</returns> public virtual int SendBlogCommentNotificationMessage(BlogComment blogComment, int languageId) { if (blogComment == null) throw new ArgumentNullException("blogComment"); var store = _storeContext.CurrentStore; languageId = EnsureLanguageIsActive(languageId, store.Id); var messageTemplate = GetLocalizedActiveMessageTemplate("Blog.BlogComment", languageId, store.Id); if (messageTemplate == null) return 0; //tokens var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens, store); _messageTokenProvider.AddBlogCommentTokens(tokens, blogComment); //event notification _eventPublisher.MessageTokensAdded(messageTemplate, tokens); var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); var toEmail = emailAccount.Email; var toName = emailAccount.DisplayName; // use customer email as reply address var replyTo = GetReplyToEmail(blogComment.Customer); return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName, replyTo.Item1, replyTo.Item2); }
public void Can_get_customer_content_by_type() { var customer = SaveAndLoadEntity<Customer>(GetTestCustomer(), false); var product = SaveAndLoadEntity<Product>(GetTestProduct(), false); var productReview = new ProductReview { Customer = customer, Product = product, Title = "Test", ReviewText = "A review", IpAddress = "192.168.1.1", IsApproved = true, CreatedOnUtc = new DateTime(2010, 01, 01), UpdatedOnUtc = new DateTime(2010, 01, 02), }; var productReviewHelpfulness = new ProductReviewHelpfulness { Customer = customer, ProductReview = productReview, WasHelpful = true, IpAddress = "192.168.1.1", IsApproved = true, CreatedOnUtc = new DateTime(2010, 01, 03), UpdatedOnUtc = new DateTime(2010, 01, 04) }; var blogComment = new BlogComment { Customer = customer, IpAddress = "192.168.1.1", IsApproved = true, CreatedOnUtc = new DateTime(2010, 01, 03), UpdatedOnUtc = new DateTime(2010, 01, 04), BlogPost = new BlogPost() { Title = "Title 1", Body = "Body 1", AllowComments = true, CreatedOnUtc = new DateTime(2010, 01, 01), Language = new Language() { Name = "English", LanguageCulture = "en-Us", } } }; var table = context.Set<CustomerContent>(); table.RemoveRange(table.ToList()); table.Add(productReview); table.Add(productReviewHelpfulness); table.Add(blogComment); context.SaveChanges(); context.Dispose(); context = new SmartObjectContext(GetTestDbName()); var query = context.Set<CustomerContent>(); query.ToList().Count.ShouldEqual(3); var dbReviews = query.OfType<ProductReview>().ToList(); dbReviews.Count().ShouldEqual(1); dbReviews.First().ReviewText.ShouldEqual("A review"); var dbHelpfulnessRecords = query.OfType<ProductReviewHelpfulness>().ToList(); dbHelpfulnessRecords.Count().ShouldEqual(1); dbHelpfulnessRecords.First().WasHelpful.ShouldEqual(true); var dbBlogCommentRecords = query.OfType<BlogComment>().ToList(); dbBlogCommentRecords.Count().ShouldEqual(1); }