public ActionResult Index() { var dataContext = new CoffeeReviewEntities(); IQueryable <SelectListItem> productList = from p in dataContext.products select new SelectListItem() { Text = p.product_vendor + " - " + p.product_name, Value = p.product_id.ToString() }; ReviewSubmit reviewSubmit = new ReviewSubmit(); reviewSubmit.products = productList; return(View(reviewSubmit)); }
public ActionResult Index(int pid = 0) { var dataContext = new CoffeeReviewEntities(); IQueryable <ReviewDisplay> filteredReviewDisplay = from r in dataContext.reviews join p in dataContext.products on r.product_id equals p.product_id join re in dataContext.reviewers on r.reviewer_id equals re.reviewer_id where p.product_id == pid select new ReviewDisplay() { review_id = r.review_id, review_description = r.review_description, review_rating = r.review_rating, reviewer_first_name = re.reviewer_first_name, product_name = p.product_name, product_vendor = p.product_vendor }; return(View(filteredReviewDisplay)); }
public ActionResult Index() { var dataContext = new CoffeeReviewEntities(); IQueryable <ReviewDisplay> reviewDisplay = from r in dataContext.reviews join p in dataContext.products on r.product_id equals p.product_id join re in dataContext.reviewers on r.reviewer_id equals re.reviewer_id group new { r.review_rating } by new { p.product_name, p.product_vendor, p.product_id } into g select new ReviewDisplay() { review_rating = g.Average(x => x.review_rating), review_count = g.Count(x => x.review_rating.HasValue), product_name = g.Key.product_name, product_vendor = g.Key.product_vendor, product_id = g.Key.product_id }; return(View(reviewDisplay)); }