public static IEnumerable <ProductCell> ClassifyResult(SearchFilters searchFilters) { FancyStoreEntities db = new FancyStoreEntities(); IQueryable <ProductColor> preproducts = db.ProductColors.AsQueryable(); var products = ProductMethod.CreateProductCells(preproducts).OrderBy(c => c.ProductID); IEnumerable <ProductCell> result; result = products.Where(p => p.ProductName.Contains(searchFilters.Keyword)); if (result.Count() > 0) { if (searchFilters.CategorySID != null) { result = result.Where(p => searchFilters.CategorySID.Contains(p.CategorySID)); } if (searchFilters.ColorID != null) { result = result.Where(p => searchFilters.ColorID.Contains(p.ColorID)); } if (searchFilters.SizeID != null) { switch (searchFilters.SizeID.Count) { case 1: result = result.Where(p => p.SizeID.Contains(searchFilters.SizeID[0])); break; case 2: result = result.Where(p => p.SizeID.Contains(searchFilters.SizeID[0]) || p.SizeID.Contains(searchFilters.SizeID[1])); break; case 3: result = result.Where(p => p.SizeID.Contains(searchFilters.SizeID[0]) || p.SizeID.Contains(searchFilters.SizeID[1]) || p.SizeID.Contains(searchFilters.SizeID[2])); break; case 4: result = result.Where(p => p.SizeID.Contains(searchFilters.SizeID[0]) || p.SizeID.Contains(searchFilters.SizeID[1]) || p.SizeID.Contains(searchFilters.SizeID[2]) || p.SizeID.Contains(p.SizeID[3])); break; } } if (searchFilters.MaxSunitPrice != 0) { result = result.Where(p => p.SUnitPrice >= searchFilters.MinSunitPrice && p.SUnitPrice <= searchFilters.MaxSunitPrice); } if (searchFilters.ActivityID != 0) { var activityname = db.Activities.Where(a => a.ActivityID == searchFilters.ActivityID && a.EndDate >= DateTime.Now).FirstOrDefault().ActivityName; result = result.Where(p => p.ActivityName == activityname); } } return(result); }
public ActionResult GetProduct(int id = 0, int orderid = 1, int page = 1) { var preproducts = db.ProductColors.Where(p => p.Product.ActivityProducts.Where(a => a.Activity.EndDate >= DateTime.Now).FirstOrDefault().Activity.ActivityID == id && p.Product.ActivityProducts.Where(a => a.Activity.EndDate >= DateTime.Now).FirstOrDefault().Activity.ActivityName != null); var products = ProductMethod.CreateProductCells(preproducts); int pages = products.Count(); var orderresult = ProductMethod.SetCellsByOrder(products, orderid).Skip((page - 1) * 16).Take(16); return(Json(new { pages = pages, datas = orderresult.ToList() }, JsonRequestBehavior.AllowGet)); }
//塊狀商品展示 public ActionResult GetProduct(int id = 1, int sid = 0, int orderid = 1, int page = 1) { IQueryable <ProductColor> preproducts = (sid != 0) ? db.ProductColors.Where(p => p.Product.CategorySID == sid) : db.ProductColors.Where(p => p.Product.CategorySmall.CategoryMID == id); var products = ProductMethod.CreateProductCells(preproducts); int pages = products.Count(); var orderresult = ProductMethod.SetCellsByOrder(products, orderid).Skip((page - 1) * 16).Take(16); return(Json(new { pages = pages, datas = orderresult.ToList() }, JsonRequestBehavior.AllowGet)); }