public IActionResult Index() { var viewModel = new DisplayCategoryViewModel(); viewModel.CategoryList = _context.Categories.ToList(); viewModel.Products = _context.Products.ToList(); return(View(viewModel)); }
public IActionResult Show(string slug) { var viewModel = new DisplayCategoryViewModel(); viewModel.CurrentPage = slug; viewModel.Products = _context.Products .Include(x => x.ProductCategory) .Where(x => x.ProductCategory.CategoryName == slug) .ToList(); return(View(viewModel)); }
public IActionResult Index(Guid id) { var parent = _dbContext.Categories .Include(x => x.ParentCategory) .First(x => x.Id == id); var categories = _dbContext.Categories .Include(x => x.ParentCategory) .Where(x => x.ParentCategory.Id == id); if (categories.Count() == 0) { return(RedirectToAction(nameof(ProductController.Index), "Product", new { id })); } var model = new DisplayCategoryViewModel { ParentCategory = parent, Categories = categories }; return(View(model)); }