本文整理汇总了C#中Nop.Core.Domain.Catalog.ProductReview类的典型用法代码示例。如果您正苦于以下问题:C# ProductReview类的具体用法?C# ProductReview怎么用?C# ProductReview使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ProductReview类属于Nop.Core.Domain.Catalog命名空间,在下文中一共展示了ProductReview类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PrepareProductReviewModel
protected void PrepareProductReviewModel(ProductReviewModel model,
ProductReview productReview, bool excludeProperties, bool formatReviewText)
{
if (model == null)
throw new ArgumentNullException("model");
if (productReview == null)
throw new ArgumentNullException("productReview");
model.Id = productReview.Id;
model.ProductId = productReview.ProductId;
model.ProductName = productReview.Product.Name;
model.CustomerId = productReview.CustomerId;
var customer = productReview.Customer;
model.CustomerInfo = customer.IsRegistered() ? customer.Email : _localizationService.GetResource("Admin.Customers.Guest");
model.Rating = productReview.Rating;
model.CreatedOn = _dateTimeHelper.ConvertToUserTime(productReview.CreatedOnUtc, DateTimeKind.Utc);
if (!excludeProperties)
{
model.Title = productReview.Title;
if (formatReviewText)
model.ReviewText = Core.Html.HtmlHelper.FormatText(productReview.ReviewText, false, true, false, false, false, false);
else
model.ReviewText = productReview.ReviewText;
model.IsApproved = productReview.IsApproved;
}
}
示例2: SendProductReviewNotificationMessage
/// <summary>
/// Sends a product review notification message to a store owner
/// </summary>
/// <param name="productReview">Product review</param>
/// <param name="languageId">Message language identifier</param>
/// <returns>Queued email identifier</returns>
public virtual int SendProductReviewNotificationMessage(ProductReview productReview,
int languageId)
{
if (productReview == null)
throw new ArgumentNullException("productReview");
var store = _storeContext.CurrentStore;
languageId = EnsureLanguageIsActive(languageId, store.Id);
var messageTemplate = GetActiveMessageTemplate("Product.ProductReview", 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.AddProductReviewTokens(tokens, productReview);
_messageTokenProvider.AddCustomerTokens(tokens, productReview.Customer);
//event notification
_eventPublisher.MessageTokensAdded(messageTemplate, tokens);
var toEmail = emailAccount.Email;
var toName = emailAccount.DisplayName;
return SendNotification(messageTemplate, emailAccount,
languageId, tokens,
toEmail, toName);
}
示例3: AddProductReviewTokens
public virtual void AddProductReviewTokens(IList<Token> tokens, ProductReview productReview)
{
tokens.Add(new Token("ProductReview.ProductName", productReview.Product.Name));
//event notification
_eventPublisher.EntityTokensAdded(productReview, tokens);
}
示例4: ProductReviewsAdd
public ActionResult ProductReviewsAdd(int productId, ProductReviewsModel model, bool captchaValid)
{
var product = _productService.GetProductById(productId);
if (product == null || product.Deleted || !product.Published || !product.AllowCustomerReviews)
return RedirectToRoute("HomePage");
//validate CAPTCHA
if (_captchaSettings.Enabled && _captchaSettings.ShowOnProductReviewPage && !captchaValid)
{
ModelState.AddModelError("", _localizationService.GetResource("Common.WrongCaptcha"));
}
if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
{
ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
}
if (ModelState.IsValid)
{
//save review
int rating = model.AddProductReview.Rating;
if (rating < 1 || rating > 5)
rating = _catalogSettings.DefaultProductRatingValue;
bool isApproved = !_catalogSettings.ProductReviewsMustBeApproved;
var productReview = new ProductReview
{
ProductId = product.Id,
CustomerId = _workContext.CurrentCustomer.Id,
Title = model.AddProductReview.Title,
ReviewText = model.AddProductReview.ReviewText,
Rating = rating,
HelpfulYesTotal = 0,
HelpfulNoTotal = 0,
IsApproved = isApproved,
CreatedOnUtc = DateTime.UtcNow,
};
product.ProductReviews.Add(productReview);
_productService.UpdateProduct(product);
//update product totals
_productService.UpdateProductReviewTotals(product);
//notify store owner
if (_catalogSettings.NotifyStoreOwnerAboutNewProductReviews)
_workflowMessageService.SendProductReviewNotificationMessage(productReview, _localizationSettings.DefaultAdminLanguageId);
//activity log
_customerActivityService.InsertActivity("PublicStore.AddProductReview", _localizationService.GetResource("ActivityLog.PublicStore.AddProductReview"), product.Name);
//raise event
if (productReview.IsApproved)
_eventPublisher.Publish(new ProductReviewApprovedEvent(productReview));
PrepareProductReviewsModel(model, product);
model.AddProductReview.Title = null;
model.AddProductReview.ReviewText = null;
model.AddProductReview.SuccessfullyAdded = true;
if (!isApproved)
model.AddProductReview.Result = _localizationService.GetResource("Reviews.SeeAfterApproving");
else
model.AddProductReview.Result = _localizationService.GetResource("Reviews.SuccessfullyAdded");
return View(model);
}
//If we got this far, something failed, redisplay form
PrepareProductReviewsModel(model, product);
return View(model);
}
示例5: InsertProductReview
/// <summary>
/// Inserts a product review
/// </summary>
/// <param name="productPicture">Product picture</param>
public virtual void InsertProductReview(ProductReview productReview)
{
if (productReview == null)
throw new ArgumentNullException("productPicture");
_productReviewRepository.Insert(productReview);
//event notification
_eventPublisher.EntityInserted(productReview);
}
示例6: InstallProducts
//.........这里部分代码省略.........
AddProductTag(productBuildComputer, "computer");
AddProductTag(productNikonD5500DSLR, "cool");
AddProductTag(productNikonD5500DSLR, "camera");
AddProductTag(productLeica, "camera");
AddProductTag(productLeica, "cool");
AddProductTag(productDigitalStorm, "cool");
AddProductTag(productDigitalStorm, "computer");
AddProductTag(productWindows8Pro, "awesome");
AddProductTag(productWindows8Pro, "computer");
AddProductTag(productCustomTShirt, "cool");
AddProductTag(productCustomTShirt, "shirt");
AddProductTag(productCustomTShirt, "apparel");
AddProductTag(productElegantGemstoneNecklace, "jewelry");
AddProductTag(productElegantGemstoneNecklace, "awesome");
AddProductTag(productFlowerGirlBracelet, "awesome");
AddProductTag(productFlowerGirlBracelet, "jewelry");
AddProductTag(productFirstPrizePies, "book");
AddProductTag(productAdidas, "cool");
AddProductTag(productAdidas, "shoes");
AddProductTag(productAdidas, "apparel");
AddProductTag(productLenovoIdeaCentre, "awesome");
AddProductTag(productLenovoIdeaCentre, "computer");
AddProductTag(productSamsungSeries, "nice");
AddProductTag(productSamsungSeries, "computer");
AddProductTag(productSamsungSeries, "compact");
AddProductTag(productHpSpectre, "nice");
AddProductTag(productHpSpectre, "computer");
AddProductTag(productHpEnvy, "computer");
AddProductTag(productHpEnvy, "cool");
AddProductTag(productHpEnvy, "compact");
AddProductTag(productObeyHat, "apparel");
AddProductTag(productObeyHat, "cool");
AddProductTag(productLeviJeans, "cool");
AddProductTag(productLeviJeans, "jeans");
AddProductTag(productLeviJeans, "apparel");
AddProductTag(productSoundForge, "game");
AddProductTag(productSoundForge, "computer");
AddProductTag(productSoundForge, "cool");
AddProductTag(productNightVision, "awesome");
AddProductTag(productNightVision, "digital");
AddProductTag(productSunglasses, "apparel");
AddProductTag(productSunglasses, "cool");
AddProductTag(productHtcOneMini, "awesome");
AddProductTag(productHtcOneMini, "compact");
AddProductTag(productHtcOneMini, "cell");
AddProductTag(productIfYouWait, "digital");
AddProductTag(productIfYouWait, "awesome");
AddProductTag(productNokiaLumia, "awesome");
AddProductTag(productNokiaLumia, "cool");
AddProductTag(productNokiaLumia, "camera");
AddProductTag(productScienceAndFaith, "digital");
AddProductTag(productScienceAndFaith, "awesome");
AddProductTag(productPrideAndPrejudice, "book");
AddProductTag(productLenovoThinkpad, "awesome");
AddProductTag(productLenovoThinkpad, "computer");
AddProductTag(productLenovoThinkpad, "compact");
AddProductTag(productNikeZoom, "jeans");
AddProductTag(productNikeZoom, "cool");
AddProductTag(productNikeZoom, "apparel");
AddProductTag(productEngagementRing, "jewelry");
AddProductTag(productEngagementRing, "awesome");
#endregion
//reviews
var random = new Random();
foreach (var product in allProducts)
{
if (product.ProductType != ProductType.SimpleProduct)
continue;
//only 3 of 4 products will have reviews
if (random.Next(4) == 3)
continue;
//rating from 4 to 5
var rating = random.Next(4, 6);
var productReview = new ProductReview
{
_id = ObjectId.GenerateNewId().ToString(),
CustomerId = defaultCustomer.Id,
ProductId = product.Id,
IsApproved = true,
Title = "Some sample review",
ReviewText = string.Format("This sample review is for the {0}. I've been waiting for this product to be available. It is priced just right.", product.Name),
Rating = rating,
HelpfulYesTotal = 0,
HelpfulNoTotal = 0,
CreatedOnUtc = DateTime.UtcNow,
};
_productReviewRepository.Insert(productReview);
product.ApprovedRatingSum = rating;
product.ApprovedTotalReviews = product.ApprovedTotalReviews+1;
}
_productRepository.Update(allProducts);
}
示例7: AddProductReviewTokens
public virtual void AddProductReviewTokens(IList<Token> tokens, ProductReview productReview)
{
tokens.Add(new Token("ProductReview.ProductName", productReview.Product.Name));
}
示例8: PrepareProductReviewModel
protected void PrepareProductReviewModel(ProductReviewModel model,
ProductReview productReview, bool excludeProperties, bool formatReviewText)
{
if (model == null)
throw new ArgumentNullException("model");
if (productReview == null)
throw new ArgumentNullException("productReview");
model.Id = productReview.Id;
model.ProductId = productReview.ProductId;
model.ProductName = productReview.Product.Name;
model.CustomerId = productReview.CustomerId;
model.IpAddress = productReview.IpAddress;
model.Rating = productReview.Rating;
model.CreatedOn = _dateTimeHelper.ConvertToUserTime(productReview.CreatedOnUtc, DateTimeKind.Utc);
if (!excludeProperties)
{
model.Title = productReview.Title;
if (formatReviewText)
model.ReviewText = Core.Html.HtmlHelper.FormatText(productReview.ReviewText, false, true, false, false, false, false);
else
model.ReviewText = productReview.ReviewText;
model.IsApproved = productReview.IsApproved;
}
}
示例9: Can_get_customer_content_by_type
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);
}
示例10: DeleteProductReview
/// <summary>
/// Deletes a product review
/// </summary>
/// <param name="productReview">Product review</param>
public virtual void DeleteProductReview(ProductReview productReview)
{
if (productReview == null)
throw new ArgumentNullException("productReview");
_productReviewRepository.Delete(productReview);
}
示例11: Can_save_productReview_with_helpfulness
public void Can_save_productReview_with_helpfulness()
{
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)
};
productReview.ProductReviewHelpfulnessEntries.Add
(
new ProductReviewHelpfulness
{
Customer = customer,
WasHelpful = true,
IpAddress = "192.168.1.1",
IsApproved = true,
CreatedOnUtc = new DateTime(2010, 01, 03),
UpdatedOnUtc = new DateTime(2010, 01, 04)
}
);
var fromDb = SaveAndLoadEntity(productReview);
fromDb.ShouldNotBeNull();
fromDb.ReviewText.ShouldEqual("A review");
fromDb.ProductReviewHelpfulnessEntries.ShouldNotBeNull();
(fromDb.ProductReviewHelpfulnessEntries.Count == 1).ShouldBeTrue();
fromDb.ProductReviewHelpfulnessEntries.First().WasHelpful.ShouldEqual(true);
}
示例12: EditExtendedReviewPost
public ActionResult EditExtendedReviewPost(int OrderId, int ProductId, PublicReviewEditModel model)
{
var ProductReview = model.AddProductReviewModel;
var VendorReview = model.VendorReviewListModel;
var customer = _workContext.CurrentCustomer;
var product = _productService.GetProductById(ProductId);
if (product == null || product.Deleted || !product.Published || !product.AllowCustomerReviews)
return RedirectToRoute("HomePage");
if (ModelState.IsValid)
{
var canCustomerReviewVendor = _extendedVendorService.CanCustomerReviewVendor(product.VendorId, customer.Id, OrderId);
if (!canCustomerReviewVendor)
{
return InvokeHttp404();
}
var customerProductReviews = product.ProductReviews.Where(m => m.CustomerId == customer.Id).OrderByDescending(m => m.CreatedOnUtc);
var rating = ProductReview.Rating;
if (rating < 1 || rating > 5)
rating = _catalogSettings.DefaultProductRatingValue;
var isApproved = !_catalogSettings.ProductReviewsMustBeApproved;
ProductReview productReview;
if (customerProductReviews.Any())
{
productReview = customerProductReviews.First();
productReview.Title = ProductReview.Title;
productReview.ReviewText = ProductReview.ReviewText;
productReview.Rating = rating;
productReview.IsApproved = isApproved;
//updating
}
else
{
productReview = new ProductReview() {
ProductId = product.Id,
CustomerId = _workContext.CurrentCustomer.Id,
Title = ProductReview.Title,
ReviewText = ProductReview.ReviewText,
Rating = rating,
HelpfulYesTotal = 0,
HelpfulNoTotal = 0,
IsApproved = isApproved,
CreatedOnUtc = DateTime.UtcNow,
};
product.ProductReviews.Add(productReview);
}
_productService.UpdateProduct(product);
//update product totals
_productService.UpdateProductReviewTotals(product);
//notify store owner
if (_catalogSettings.NotifyStoreOwnerAboutNewProductReviews)
_workflowMessageService.SendProductReviewNotificationMessage(productReview, _localizationSettings.DefaultAdminLanguageId);
//activity log
_customerActivityService.InsertActivity("PublicStore.AddProductReview", _localizationService.GetResource("ActivityLog.PublicStore.AddProductReview"), product.Name);
rating = VendorReview.Rating;
if (rating < 1 || rating > 5)
rating = _catalogSettings.DefaultProductRatingValue;
var vendorReview = _extendedVendorService.GetVendorReview(product.VendorId, customer.Id, OrderId, ProductId);
if (vendorReview == null)
{
vendorReview = new VendorReview() {
IsApproved = isApproved,
CertifiedBuyerReview = true,
DisplayCertifiedBadge = true,
CreatedOnUTC = DateTime.Now,
CustomerId = customer.Id,
HelpfulnessNoTotal = 0,
HelpfulnessYesTotal = 0,
OrderId = OrderId,
ProductId = product.Id,
Rating = rating,
ReviewText = VendorReview.ReviewText,
Title = VendorReview.Title,
VendorId = product.VendorId
};
}
else
{
vendorReview.IsApproved = isApproved;
vendorReview.ReviewText = VendorReview.ReviewText;
vendorReview.Title = VendorReview.Title;
vendorReview.Rating = rating;
vendorReview.HelpfulnessYesTotal = 0;
vendorReview.HelpfulnessNoTotal = 0;
}
_extendedVendorService.SaveVendorReview(vendorReview);
return RedirectToRoute("ExtendedVendorReviewCenterLoader", new { Redirection = true });
}
else
{
return RedirectToRoute("HomePage");
}
//.........这里部分代码省略.........
示例13: AddProductReviewTokens
public virtual void AddProductReviewTokens(IList<Token> tokens, ProductReview productReview)
{
var product = EngineContext.Current.Resolve<IProductService>().GetProductById(productReview.ProductId);
tokens.Add(new Token("ProductReview.ProductName", product.Name));
//event notification
_eventPublisher.EntityTokensAdded(productReview, tokens);
}
示例14: GenerateTokens
private IList<Token> GenerateTokens(ProductReview productReview)
{
var tokens = new List<Token>();
_messageTokenProvider.AddStoreTokens(tokens);
_messageTokenProvider.AddProductReviewTokens(tokens, productReview);
return tokens;
}
示例15: ProductReviewsAdd
public ActionResult ProductReviewsAdd(int productId, ProductReviewsModel model)
{
var product = _productService.GetProductById(productId);
if (product == null || product.Deleted || !product.Published || !product.AllowCustomerReviews)
return RedirectToAction("Index", "Home");
if (_workContext.CurrentCustomer.IsGuest() && !_catalogSettings.AllowAnonymousUsersToReviewProduct)
{
ModelState.AddModelError("", _localizationService.GetResource("Reviews.OnlyRegisteredUsersCanWriteReviews"));
}
if (ModelState.IsValid)
{
//save review
int rating = model.AddProductReview.Rating;
if (rating < 1 || rating > 5)
rating = _catalogSettings.DefaultProductRatingValue;
bool isApproved = !_catalogSettings.ProductReviewsMustBeApproved;
var productReview = new ProductReview()
{
ProductId = product.Id,
CustomerId = _workContext.CurrentCustomer.Id,
IpAddress = _webHelper.GetCurrentIpAddress(),
Title = model.AddProductReview.Title,
ReviewText = model.AddProductReview.ReviewText,
Rating = rating,
HelpfulYesTotal = 0,
HelpfulNoTotal = 0,
IsApproved = isApproved,
CreatedOnUtc = DateTime.UtcNow,
UpdatedOnUtc = DateTime.UtcNow,
};
_customerContentService.InsertCustomerContent(productReview);
//update product totals
_productService.UpdateProductReviewTotals(product);
//notify store owner
if (_catalogSettings.NotifyStoreOwnerAboutNewProductReviews)
_workflowMessageService.SendProductReviewNotificationMessage(productReview, _localizationSettings.DefaultAdminLanguageId);
PrepareProductReviewsModel(model, product);
model.AddProductReview.Title = null;
model.AddProductReview.ReviewText = null;
model.AddProductReview.SuccessfullyAdded = true;
if (!isApproved)
model.AddProductReview.Result = _localizationService.GetResource("Reviews.SeeAfterApproving");
else
model.AddProductReview.Result = _localizationService.GetResource("Reviews.SuccessfullyAdded");
return View(model);
}
//If we got this far, something failed, redisplay form
PrepareProductReviewsModel(model, product);
return View(model);
}