public ActionResult Edit(ProductReviewModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var productReview = _customerContentService.GetCustomerContentById(model.Id) as ProductReview; if (productReview == null) { return(RedirectToAction("List")); } if (ModelState.IsValid) { productReview.Title = model.Title; productReview.ReviewText = model.ReviewText; productReview.IsApproved = model.IsApproved; _customerContentService.UpdateCustomerContent(productReview); //update product totals _productService.UpdateProductReviewTotals(productReview.Product); _customerService.RewardPointsForProductReview(productReview.Customer, productReview.Product, productReview.IsApproved); NotifySuccess(_localizationService.GetResource("Admin.Catalog.ProductReviews.Updated")); return(continueEditing ? RedirectToAction("Edit", productReview.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form PrepareProductReviewModel(model, productReview, true, false); return(View(model)); }
public ActionResult Edit(ProductReviewModel model, bool continueEditing) { var productReview = _customerContentService.GetCustomerContentById(model.Id) as ProductReview; if (productReview == null) { return(RedirectToAction("List")); } if (ModelState.IsValid) { productReview.Title = model.Title; productReview.ReviewText = model.ReviewText; productReview.IsApproved = model.IsApproved; _customerContentService.UpdateCustomerContent(productReview); _productService.UpdateProductReviewTotals(productReview.Product); _customerService.RewardPointsForProductReview(productReview.Customer, productReview.Product, productReview.IsApproved); NotifySuccess(T("Admin.Catalog.ProductReviews.Updated")); return(continueEditing ? RedirectToAction("Edit", productReview.Id) : RedirectToAction("List")); } PrepareProductReviewModel(model, productReview, true, false); return(View(model)); }
public ActionResult Edit(ProductReviewModel model, bool continueEditing) { if (!_permissionService.Authorize(StandardPermissionProvider.ManageCatalog)) { return(AccessDeniedView()); } var productReview = _customerContentService.GetCustomerContentById(model.Id) as ProductReview; if (productReview == null) { throw new ArgumentException("No product review found with the specified id"); } if (ModelState.IsValid) { productReview.Title = model.Title; productReview.ReviewText = model.ReviewText; productReview.IsApproved = model.IsApproved; productReview.UpdatedOnUtc = DateTime.UtcNow; _customerContentService.UpdateCustomerContent(productReview); //update product totals _productService.UpdateProductReviewTotals(productReview.Product); SuccessNotification(_localizationService.GetResource("Admin.Catalog.ProductReviews.Updated")); return(continueEditing ? RedirectToAction("Edit", productReview.Id) : RedirectToAction("List")); } //If we got this far, something failed, redisplay form PrepareProductReviewModel(model, productReview, true, false); return(View(model)); }
public ActionResult SetReviewHelpfulness(int productReviewId, bool washelpful) { var productReview = _customerContentService.GetCustomerContentById(productReviewId) as ProductReview; if (productReview == null) { throw new ArgumentException(T("Reviews.NotFound", productReviewId)); } if (_services.WorkContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct) { return(Json(new { Success = false, Result = T("Reviews.Helpfulness.OnlyRegistered").Text, TotalYes = productReview.HelpfulYesTotal, TotalNo = productReview.HelpfulNoTotal })); } //customers aren't allowed to vote for their own reviews if (productReview.CustomerId == _services.WorkContext.CurrentCustomer.Id) { return(Json(new { Success = false, Result = T("Reviews.Helpfulness.YourOwnReview").Text, TotalYes = productReview.HelpfulYesTotal, TotalNo = productReview.HelpfulNoTotal })); } // delete previous helpfulness var oldPrh = (from prh in productReview.ProductReviewHelpfulnessEntries where prh.CustomerId == _services.WorkContext.CurrentCustomer.Id select prh).FirstOrDefault(); if (oldPrh != null) { _customerContentService.DeleteCustomerContent(oldPrh); } // insert new helpfulness var newPrh = new ProductReviewHelpfulness { ProductReviewId = productReview.Id, CustomerId = _services.WorkContext.CurrentCustomer.Id, IpAddress = _services.WebHelper.GetCurrentIpAddress(), WasHelpful = washelpful, IsApproved = true, //always approved }; _customerContentService.InsertCustomerContent(newPrh); // new totals int helpfulYesTotal = (from prh in productReview.ProductReviewHelpfulnessEntries where prh.WasHelpful select prh).Count(); int helpfulNoTotal = (from prh in productReview.ProductReviewHelpfulnessEntries where !prh.WasHelpful select prh).Count(); productReview.HelpfulYesTotal = helpfulYesTotal; productReview.HelpfulNoTotal = helpfulNoTotal; _customerContentService.UpdateCustomerContent(productReview); return(Json(new { Success = true, Result = T("Reviews.Helpfulness.SuccessfullyVoted").Text, TotalYes = productReview.HelpfulYesTotal, TotalNo = productReview.HelpfulNoTotal })); }