public virtual ActionResult ArticleReviews(int articleId) { var article = _articleService.GetArticleById(articleId); if (article == null || article.Deleted || !article.Published || !article.AllowCustomerReviews) { return(RedirectToRoute("HomePage")); } var model = new ArticleReviewsModel(); model = _articleModelFactory.PrepareArticleReviewsModel(model, article); //only registered users can leave reviews if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewArticle) { ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews")); } if (_catalogSettings.ArticleReviewPossibleOnlyAfterPurchasing && !_subscriptionService.SearchSubscriptions(customerId: _workContext.CurrentCustomer.Id, articleId: articleId, osIds: new List <int> { (int)SubscriptionStatus.Complete }).Any()) { ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ArticleReviewPossibleOnlyAfterPurchasing")); } //default value model.AddArticleReview.Rating = _catalogSettings.DefaultArticleRatingValue; return(View(model)); }
public ActionResult ArticleDetailReviews(int articleId) { var article = _articleService.GetArticleById(articleId); if (article == null || !article.AllowUserReviews) { return(Content("")); } var model = new ArticleReviewsModel(); _helper.PrepareArticleReviewsModel(model, article); return(PartialView(model)); }
public ActionResult Reviews(int id) { var article = _articleService.GetArticleById(id); if (article == null || article.Deleted || article.StatusFormat != StatusFormat.Norma || !article.AllowUserReviews) { return(HttpNotFound()); } var model = new ArticleReviewsModel(); _helper.PrepareArticleReviewsModel(model, article); //only registered users can leave reviews if (_services.WorkContext.CurrentUser.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewArticle) { ModelState.AddModelError("", T("Reviews.OnlyRegisteredUsersCanWriteReviews")); } //default value model.AddArticleReview.Rating = _catalogSettings.DefaultArticleRatingValue; return(View(model)); }
// [CaptchaValidator] public ActionResult ReviewsAdd(int id, ArticleReviewsModel model, bool captchaValid) { var article = _articleService.GetArticleById(id); if (article == null || article.Deleted || article.StatusFormat != StatusFormat.Norma || !article.AllowUserReviews) { return(HttpNotFound()); } if (_services.WorkContext.CurrentUser.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewArticle) { ModelState.AddModelError("", T("Reviews.OnlyRegisteredUsersCanWriteReviews")); } if (ModelState.IsValid) { //save review int rating = model.AddArticleReview.Rating; if (rating < 1 || rating > 5) { rating = _catalogSettings.DefaultArticleRatingValue; } bool isApproved = !_catalogSettings.ArticleReviewsMustBeApproved; var user = _services.WorkContext.CurrentUser; var articleReview = new ArticleReview() { ArticleId = article.Id, UserId = user.Id, IpAddress = _services.WebHelper.GetCurrentIpAddress(), Rating = rating, HelpfulYesTotal = 0, HelpfulNoTotal = 0, IsApproved = isApproved, CreatedOnUtc = DateTime.UtcNow, ModifiedOnUtc = DateTime.UtcNow, }; _userContentService.InsertUserContent(articleReview); //update article totals _articleService.UpdateArticleReviewTotals(article); //activity log _services.UserActivity.InsertActivity("PublicStore.AddArticleReview", T("ActivityLog.PublicStore.AddArticleReview"), article.Title); //if (isApproved) // _userService.RewardPointsForArticleReview(user, article, true); _helper.PrepareArticleReviewsModel(model, article); model.AddArticleReview.SuccessfullyAdded = true; if (!isApproved) { model.AddArticleReview.Result = T("Reviews.SeeAfterApproving"); } else { model.AddArticleReview.Result = T("Reviews.SuccessfullyAdded"); } return(View(model)); } //If we got this far, something failed, redisplay form _helper.PrepareArticleReviewsModel(model, article); return(View(model)); }
public virtual ActionResult ArticleReviewsAdd(int articleId, ArticleReviewsModel model, bool captchaValid) { var article = _articleService.GetArticleById(articleId); if (article == null || article.Deleted || !article.Published || !article.AllowCustomerReviews) { return(RedirectToRoute("HomePage")); } //validate CAPTCHA if (_captchaSettings.Enabled && _captchaSettings.ShowOnArticleReviewPage && !captchaValid) { ModelState.AddModelError("", _captchaSettings.GetWrongCaptchaMessage(_localizationService)); } if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewArticle) { ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews")); } if (_catalogSettings.ArticleReviewPossibleOnlyAfterPurchasing && !_subscriptionService.SearchSubscriptions(customerId: _workContext.CurrentCustomer.Id, articleId: articleId, osIds: new List <int> { (int)SubscriptionStatus.Complete }).Any()) { ModelState.AddModelError(string.Empty, _localizationService.GetResource("Reviews.ArticleReviewPossibleOnlyAfterPurchasing")); } if (ModelState.IsValid) { //save review int rating = model.AddArticleReview.Rating; if (rating < 1 || rating > 5) { rating = _catalogSettings.DefaultArticleRatingValue; } bool isApproved = !_catalogSettings.ArticleReviewsMustBeApproved; var articleReview = new ArticleReview { ArticleId = article.Id, CustomerId = _workContext.CurrentCustomer.Id, Title = model.AddArticleReview.Title, ReviewText = model.AddArticleReview.ReviewText, Rating = rating, HelpfulYesTotal = 0, HelpfulNoTotal = 0, IsApproved = isApproved, CreatedOnUtc = DateTime.UtcNow, StoreId = _storeContext.CurrentStore.Id, }; article.ArticleReviews.Add(articleReview); _articleService.UpdateArticle(article); //update article totals _articleService.UpdateArticleReviewTotals(article); //notify store owner if (_catalogSettings.NotifyStoreOwnerAboutNewArticleReviews) { _workflowMessageService.SendArticleReviewNotificationMessage(articleReview, _localizationSettings.DefaultAdminLanguageId); } //activity log _customerActivityService.InsertActivity("PublicStore.AddArticleReview", _localizationService.GetResource("ActivityLog.PublicStore.AddArticleReview"), article.Name); //raise event if (articleReview.IsApproved) { _eventPublisher.Publish(new ArticleReviewApprovedEvent(articleReview)); } model = _articleModelFactory.PrepareArticleReviewsModel(model, article); model.AddArticleReview.Title = null; model.AddArticleReview.ReviewText = null; model.AddArticleReview.SuccessfullyAdded = true; if (!isApproved) { model.AddArticleReview.Result = _localizationService.GetResource("Reviews.SeeAfterApproving"); } else { model.AddArticleReview.Result = _localizationService.GetResource("Reviews.SuccessfullyAdded"); } return(View(model)); } //If we got this far, something failed, redisplay form model = _articleModelFactory.PrepareArticleReviewsModel(model, article); return(View(model)); }