public ActionResult Category(int id = 0, int like = 0, int brand = 0) { if (like > 0) { productLike pk = new productLike(); pk.ProductId = like; pk.DateTime = DateTime.Now; pk.Ip = Request.UserHostAddress; pk.UserId = (int)Session["id"]; db.productLikes.Add(pk); db.SaveChanges(); } var products = db.products.Where(p => p.productVerifieds.Count > 0); if (id > 0) { ViewBag.category = db.categories.Find(id).name; products = products.Where(p => p.CategoryId == id || (p.category.category2 != null && p.category.category2.id == id)); } if (brand > 0) { ViewBag.brand = db.brands.Find(brand).name; products = products.Where(p => p.BrandId == brand); } return(View(products.ToList())); }
public ActionResult All(int like = 0, int brand = 0, string search = " ", double priceFrom = 0, double priceTo = 0, string nego = "all") { ViewBag.search = search; ViewBag.brand = brand; ViewBag.priceFrom = priceFrom; ViewBag.priceTo = priceTo; ViewBag.nego = nego; if (like > 0) { productLike pk = new productLike(); pk.ProductId = like; pk.DateTime = DateTime.Now; pk.Ip = Request.UserHostAddress; pk.UserId = (int)Session["id"]; db.productLikes.Add(pk); db.SaveChanges(); } var products = db.products.Where(p => p.productVerifieds.Count > 0 && p.productCloseds.Count <= 0); if (!string.IsNullOrEmpty(search)) { products = products.Where(p => p.Description.ToLower().Contains(search.ToLower()) || p.Links.ToLower().Contains(search.ToLower()) || p.Name.ToLower().Contains(search.ToLower())); } if (priceTo > 0) { products = products.Where(p => p.OfferPrice >= priceFrom && p.OfferPrice <= priceTo); } if (brand > 0) { ViewBag.brand = db.brands.Find(brand).name; products = products.Where(p => p.BrandId == brand); } if (nego == "Fixed") { products = products.Where(p => p.Negotiable == false); } else if (nego == "Not Fixed") { products = products.Where(p => p.Negotiable == true); } return(View(products.ToList())); }