/// <summary> /// Deletes a blog comment /// </summary> /// <param name="blogComment">Blog comment</param> public virtual void DeleteBlogComment(BlogComment blogComment) { if (blogComment == null) throw new ArgumentNullException("blogComment"); _blogCommentRepository.Delete(blogComment); }
/// <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"); languageId = EnsureLanguageIsActive(languageId); var messageTemplate = GetLocalizedActiveMessageTemplate("Blog.BlogComment", languageId); if (messageTemplate == null) return 0; var blogCommentTokens = GenerateTokens(blogComment); //event notification _eventPublisher.MessageTokensAdded(messageTemplate, blogCommentTokens); var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); var toEmail = emailAccount.Email; var toName = emailAccount.DisplayName; return SendNotification(messageTemplate, emailAccount, languageId, blogCommentTokens, toEmail, toName); }
private IList<Token> GenerateTokens(BlogComment blogComment) { var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens); _messageTokenProvider.AddBlogCommentTokens(tokens, blogComment); return tokens; }
/// <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 = GetActiveMessageTemplate("Blog.BlogComment", store.Id); if (messageTemplate == null) return 0; //email account var emailAccount = GetEmailAccountOfMessageTemplate(messageTemplate, languageId); //tokens var tokens = new List<Token>(); _messageTokenProvider.AddStoreTokens(tokens, store, emailAccount); _messageTokenProvider.AddBlogCommentTokens(tokens, blogComment); _messageTokenProvider.AddCustomerTokens(tokens, blogComment.Customer); //event notification _eventPublisher.MessageTokensAdded(messageTemplate, tokens); var toEmail = emailAccount.Email; var toName = emailAccount.DisplayName; return SendNotification(messageTemplate, emailAccount, languageId, tokens, toEmail, toName); }
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 virtual void AddBlogCommentTokens(IList<Token> tokens, BlogComment blogComment) { tokens.Add(new Token("BlogComment.BlogPostTitle", blogComment.BlogPost.Title)); }
public ActionResult BlogCommentAdd(int blogPostId, BlogPostModel model, bool captchaValid) { if (!_blogSettings.Enabled) return RedirectToRoute("HomePage"); var blogPost = _blogService.GetBlogPostById(blogPostId); if (blogPost == null || !blogPost.AllowComments) return RedirectToRoute("HomePage"); 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["nop.blog.addcomment.result"] = _localizationService.GetResource("Blog.Comments.SuccessfullyAdded"); return RedirectToRoute("BlogPost", new { SeName = blogPost.GetSeName(blogPost.LanguageId, ensureTwoPublishedLanguages: false) }); } //If we got this far, something failed, redisplay form PrepareBlogPostModel(model, blogPost, true); return View(model); }
/// <summary> /// Inserts an blog post /// </summary> /// <param name="blogPost">Blog post</param> public virtual void InsertBlogComment(BlogComment blogComment) { if (blogComment == null) throw new ArgumentNullException("blogPost"); _blogCommentRepository.Insert(blogComment); //event notification _eventPublisher.EntityInserted(blogComment); }
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", } } }; context.Set<CustomerContent>().Add(productReview); context.Set<CustomerContent>().Add(productReviewHelpfulness); context.Set<CustomerContent>().Add(blogComment); context.SaveChanges(); context.Dispose(); context = new NopObjectContext(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); }
public virtual void AddBlogCommentTokens(IList<Token> tokens, BlogComment blogComment) { var blogPost = EngineContext.Current.Resolve<IBlogService>().GetBlogPostById(blogComment.BlogPostId); tokens.Add(new Token("BlogComment.BlogPostTitle", blogPost.Title)); //event notification _eventPublisher.EntityTokensAdded(blogComment, tokens); }
public ActionResult BlogCommentAdd(int blogPostId, BlogPostModel model) { if (!_blogSettings.Enabled) return RedirectToAction("Index", "Home"); var blogPost = _blogService.GetBlogPostById(blogPostId); if (blogPost == null || !blogPost.AllowComments) return RedirectToAction("Index", "Home"); if (ModelState.IsValid) { if (_workContext.CurrentCustomer.IsGuest() && !_blogSettings.AllowNotRegisteredUsersToLeaveComments) { ModelState.AddModelError("", _localizationService.GetResource("Blog.Comments.OnlyRegisteredUsersLeaveComments")); } else { 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); //notify store owner if (_blogSettings.NotifyAboutNewBlogComments) _workflowMessageService.SendBlogCommentNotificationMessage(comment, _localizationSettings.DefaultAdminLanguageId); //The text boxes should be cleared after a comment has been posted //That' why we reload the page TempData["nop.blog.addcomment.result"] = _localizationService.GetResource("Blog.Comments.SuccessfullyAdded"); return RedirectToRoute("BlogPost", new { blogPostId = blogPost.Id, SeName = blogPost.GetSeName() }); } } //If we got this far, something failed, redisplay form PrepareBlogPostModel(model, blogPost, true); return View(model); }