public ActionResult ListProductWithSubCategory(int CatID, int SubID) { //take the CatID and SubCat ID and list the aall products List <Product> myQuery = new List <Product>(); SubCategoryProducts myModel = new SubCategoryProducts(); myModel.ProductCategoryID = CatID; myModel.ProductSubCategoryID = SubID; myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).Select(s => s).ToList(); myModel.myProductList = myQuery; return(View(myModel)); }
public ActionResult ListProductWithSubCategory(int CatID, int SubID, string sortBy) { List <Product> myQuery = new List <Product>(); SubCategoryProducts myModel = new SubCategoryProducts(); switch (sortBy) { case "ascPrice": myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).OrderBy(x => x.ProductDiscountedPrice).Select(s => s).ToList(); break; case "descPrice": myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).OrderByDescending(x => x.ProductDiscountedPrice).Select(s => s).ToList(); break; case "descStar": myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).OrderByDescending(x => x.ProductStar).Select(s => s).ToList(); break; case "descRate": myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).OrderByDescending(x => x.ProductDiscountedRate).Select(s => s).ToList(); break; case "descSale": myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).OrderByDescending(x => x.ProductNumberOfSales).Select(s => s).ToList(); break; case "descDate": myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).OrderByDescending(x => x.ProductDate).Select(s => s).ToList(); break; case "descEvaluate": myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).OrderByDescending(x => x.ProductNumberOfEvaluate).Select(s => s).ToList(); break; default: myQuery = db.Product.Where(s => s.CategoryID == CatID && s.SubCategoryID == SubID).OrderBy(x => x.ProductDiscountedPrice).Select(s => s).ToList(); break; } myModel.myProductList = myQuery; myModel.ProductCategoryID = CatID; myModel.ProductSubCategoryID = SubID; return(View(myModel)); }