public ActionResult TopReviews(int howMany, List <ProductReview> reviews) { ProductReviewsViewModel model = new ProductReviewsViewModel(); // Trim List of reviews if (reviews != null) { if (reviews.Count > howMany) { model.Reviews = reviews.Take(howMany).ToList(); } else { model.Reviews = reviews; } } // Load ratings buttons ThemeManager tm = MTApp.ThemeManager(); ViewBag.Star0Url = tm.ButtonUrl("Stars0", Request.IsSecureConnection); ViewBag.Star1Url = tm.ButtonUrl("Stars1", Request.IsSecureConnection); ViewBag.Star2Url = tm.ButtonUrl("Stars2", Request.IsSecureConnection); ViewBag.Star3Url = tm.ButtonUrl("Stars3", Request.IsSecureConnection); ViewBag.Star4Url = tm.ButtonUrl("Stars4", Request.IsSecureConnection); ViewBag.Star5Url = tm.ButtonUrl("Stars5", Request.IsSecureConnection); ViewBag.AvgLabel = SiteTerms.GetTerm(SiteTermIds.AverageRating); int avg = CalculateAverageRating(reviews); ViewBag.Avg = avg; ViewBag.AvgImage = tm.ButtonUrl("Stars" + avg.ToString(), Request.IsSecureConnection); return(View(model)); }
// // GET: /ProductReviews/ public ActionResult Index(string slug) { ProductReviewsViewModel model = new ProductReviewsViewModel(); Product p = GetProductFromSlug(slug); if (p == null) { return(Redirect("~/")); } model.ProductView = new SingleProductViewModel(p, MTApp); // Titles ViewBag.Title = p.MetaTitle; if (((string)ViewBag.Title).Trim().Length < 1) { ViewBag.Title = p.ProductName; } ViewBag.Title = "Reviews: " + ViewBag.Title; ViewBag.MetaTitle = "Reviews: " + p.MetaTitle; ViewBag.MetaDescription = "Reviews: " + p.MetaDescription; ViewBag.MetaKeywords = "reviews," + p.MetaKeywords; List <ProductReview> reviews = p.ReviewsApproved; if (reviews == null) { return(Redirect("~/")); } if (reviews.Count < 1) { return(Redirect("~/")); } model.Reviews = reviews; // Load ratings buttons ThemeManager tm = MTApp.ThemeManager(); ViewBag.Star0Url = tm.ButtonUrl("Stars0", Request.IsSecureConnection); ViewBag.Star1Url = tm.ButtonUrl("Stars1", Request.IsSecureConnection); ViewBag.Star2Url = tm.ButtonUrl("Stars2", Request.IsSecureConnection); ViewBag.Star3Url = tm.ButtonUrl("Stars3", Request.IsSecureConnection); ViewBag.Star4Url = tm.ButtonUrl("Stars4", Request.IsSecureConnection); ViewBag.Star5Url = tm.ButtonUrl("Stars5", Request.IsSecureConnection); ViewBag.AvgLabel = SiteTerms.GetTerm(SiteTermIds.AverageRating); int avg = CalculateAverageRating(reviews); ViewBag.Avg = avg; ViewBag.AvgImage = tm.ButtonUrl("Stars" + avg.ToString(), Request.IsSecureConnection); return(View(model)); }
public async Task <IActionResult> Details(int id) { var product = await this.productsData .GetByIdQuery(id) .ProjectTo <ProductViewModel>() .FirstOrDefaultAsync(); var reviews = await this.reviewsData .GetByProductIdQuery(id) .ProjectTo <ReviewViewModel>() .ToListAsync(); var model = new ProductReviewsViewModel { Product = product, Reviews = reviews }; return(this.View(model)); }
//Code for the Store/ProductDetails // GET: ProductDetails public ActionResult ProductDetails(int id) { //read cookie from request HttpCookie pageCookie = Request.Cookies["pageCookie"]; if (pageCookie == null) { //no cookie found or it is expired (30 min) } else { //cookie is found, check if the cookie has the value as expected if (!string.IsNullOrEmpty(pageCookie.Values["pageId"])) { //put the cookie in a viewbag ViewBag.pageId = pageCookie.Values["pageId"].ToString(); } } var product = db.Products.SingleOrDefault(p => p.ID == id); if (product == null) { return(HttpNotFound()); } var ProductReviewsList = new ProductReviewsViewModel() { Product = product, Reviews = db.Reviews.Where(c => c.ProductID.Equals(id)).ToList().AsEnumerable() }; //average star calculation for in productDetails /*int totalReviewsCount = db.Reviews.Where(t => t.ProductID.Equals(id)).Count(); * int allStars = db.Reviews.Where(s => s.Stars.Equals(id)).Count(); * * int averageStars = allStars / totalReviewsCount;*/ ShowSidebar(); return(View(ProductReviewsList)); }
public ActionResult Index(string slug) { var model = new ProductReviewsViewModel(); var p = ParseProductFromSlug(slug); model.ProductView = new SingleProductViewModel(p, HccApp); SetPageMetaData(p); var reviews = p.ReviewsApproved; CopyReviews(model, reviews); if (reviews != null) { ViewBag.Avg = CalculateAverageRating(reviews); } return(View(model)); }
public ActionResult TopReviews(int howMany, List <ProductReview> reviews) { var model = new ProductReviewsViewModel(); // Trim List of reviews if (reviews != null) { if (reviews.Count > howMany) { CopyReviews(model, reviews.Take(howMany).ToList()); } else { CopyReviews(model, reviews); } } ViewBag.Avg = CalculateAverageRating(reviews); return(View(model)); }
private void CopyReviews(ProductReviewsViewModel model, List <ProductReview> reviews) { model.Reviews.Clear(); foreach (var productReview in reviews) { var viewModel = new ProductReviewViewModel(productReview); CustomerAccount customerAccount = null; if (productReview.UserID != "0") { customerAccount = HccApp.MembershipServices.Customers.Find(productReview.UserID); } viewModel.UserID = productReview.UserID; if (customerAccount == null) { viewModel.UserName = string.Empty; viewModel.City = string.Empty; viewModel.State = string.Empty; } else { viewModel.UserName = string.Format("{0}{1}", customerAccount.FirstName, string.IsNullOrEmpty(customerAccount.LastName) ? string.Empty : customerAccount.LastName.Substring(0, 1)); viewModel.City = customerAccount.ShippingAddress == null || string.IsNullOrEmpty(customerAccount.ShippingAddress.City) ? string.Empty : customerAccount.ShippingAddress.City; viewModel.State = customerAccount.ShippingAddress == null || string.IsNullOrEmpty(customerAccount.ShippingAddress.RegionDisplayName) ? string.Empty : customerAccount.ShippingAddress.RegionDisplayName; } model.Reviews.Add(viewModel); } }