public ActionResult Index(int?id) { IQueryable <DB.Products> products = context.Products.OrderByDescending(x => x.AddedDate).Where(x => x.isDeleted == false || x.isDeleted == null); DB.Categories category = null; if (id.HasValue) { category = context.Categories.FirstOrDefault(x => x.Id == id); var allCategories = GetChildCategories(category); allCategories.Add(category); var catIntList = allCategories.Select(x => x.Id).ToList(); //select * from Product where Category_Id in (catIntList) products = products.Where(x => catIntList.Contains(x.Category_Id)); } var viewModel = new Models.i.IndexModel() { Products = products.ToList(), Category = category }; return(View(viewModel)); }
// GET: i public ActionResult Index() { var viewModel = new Models.i.IndexModel() { Products = context.Products.ToList() }; return(View(viewModel)); }
public ActionResult Index(int id = 0) { IQueryable <DB.Products> products = context.Products; DB.Categories category = null; if (id > 0) { products = products.Where(x => x.Category_Id == id); category = context.Categories.FirstOrDefault(x => x.Id == id); } var viewModel = new Models.i.IndexModel() { Products = products.ToList(), Category = category }; return(View(viewModel)); }
public ActionResult Index(int id = 0) { IQueryable <DB.Products> products = context.Products.OrderByDescending(x => x.AddedDate).Where(x => x.IsDeleted == false || x.IsDeleted == null); DB.Categories category = null; if (id > 0) { products = products.Where(x => x.Category_Id == id); category = context.Categories.FirstOrDefault(x => x.Id == id); } var viewModel = new Models.i.IndexModel() { Products = products.ToList(), Category = category }; return(View(viewModel)); }
public ActionResult Index(int id = 0) { IQueryable <DB.Products> products = context.Products.Where(x => x.IsDeleted == false || x.IsDeleted == null); DB.Categories category = null; if (id > 0) { category = context.Categories.FirstOrDefault(x => x.Id == id); var allCategories = GetChildCategories(category); allCategories.Add(category); var catIntList = allCategories.Select(x => x.Id).ToList(); products = products.Where(x => catIntList.Contains(x.Category_Id)); } var viewModel = new Models.i.IndexModel() { Products = products.ToList(), Category = category }; return(View(viewModel)); }