// GET: Products public IActionResult Index(int?categoryId) { if (categoryId != null) { var ids = categoryCache.GetThisAndChildIds(categoryId.Value); return(View(db.Products.Where(p => ids.Contains(p.CategoryId)))); } return(View(db.Products.ToList())); }
public IActionResult Category(int?id) { if (id == null) { return(new HttpStatusCodeResult(404)); } var category = categoryCache.FromKey(id.Value); if (category == null) { return(new HttpStatusCodeResult(404)); } var ids = categoryCache.GetThisAndChildIds(id.Value); return(View(new CategoryViewModel { Category = category, Products = db.Products.Where(p => ids.Contains(p.CategoryId)), ParentHierarchy = categoryCache.GetHierarchy(category.CategoryId), Children = category.Children })); }