public IActionResult ViewCategory(int id) { Console.WriteLine("-----------View Category Route---------"); int categoryId = id; Category thisCategory = dbContext.Categories .Include(product => product.Accociated) .ThenInclude(category => category.AccociatedCategories) .FirstOrDefault(category => category.CategoryId == categoryId); List <Product> AllProducts = dbContext.Products .OrderByDescending(ch => ch.CreatedAt) .ToList(); ProductsNCategories viewModel = new ProductsNCategories(); viewModel.Products = AllProducts; viewModel.category = thisCategory; return(View(viewModel)); }
public IActionResult ViewProduct(int id) { int productId = id; Console.WriteLine("-----------View Product Route---------"); Console.WriteLine($"-----------{productId}---------"); Product thisProduct = dbContext.Products .Include(product => product.Accociated) .ThenInclude(category => category.AccociatedCategories) .FirstOrDefault(product => product.ProductId == productId); Console.WriteLine($"-----------{thisProduct.Name}---------"); List <Category> AllCategories = dbContext.Categories .OrderByDescending(ch => ch.CreatedAt) .ToList(); ProductsNCategories viewModel = new ProductsNCategories(); viewModel.Categories = AllCategories; viewModel.product = thisProduct; return(View(viewModel)); }