public ActionResult UpdateProduct(int id) { Prod = new clsProduct(); Cat = new clsCategory(); ViewBag.Category = Cat.ListCatagory().Select(i => new SelectListItem() { Text = i.CategoryName, Value = i.cid.ToString() }).ToList(); return(View(Prod.ProductList().Find(x => x.Pid == id))); }
public ActionResult ProductList(string search, string sorting_order) { Prod = new clsProduct(); var result = Prod.ProductList().ToList(); ViewBag.SortingProductName = string.IsNullOrWhiteSpace(sorting_order) ? "ProductName_Desc" : ""; ViewBag.SortingPrice = sorting_order == "Price" ? "Price_Desc" : "Price"; ViewBag.SortingModel = sorting_order == "Model" ? "Model_Desc" : "Model"; if (search != null && search != "") { result = result.Where(c => c.ProductName.ToUpper().Contains(search.ToUpper()) || c.Price.ToString().Contains(search.ToUpper()) || c.Model.ToUpper().Contains(search.ToUpper())).ToList(); } switch (sorting_order) { case "ProductName_Desc": result = result.OrderByDescending(x => x.ProductName).ToList(); break; case "Price": result = result.OrderBy(x => x.Price).ToList(); break; case "Price_Desc": result = result.OrderByDescending(x => x.Price).ToList(); break; case "Model": result = result.OrderBy(x => x.Price).ToList(); break; case "Model_Desc": result = result.OrderByDescending(x => x.Price).ToList(); break; default: result = result.OrderBy(x => x.ProductName).ToList(); break; } return(View(result)); }