public IActionResult AddProduct(CategoryAndProductsViewModel modelData) { Association newAssociation = modelData.NewAssociation; dbContext.Add(newAssociation); dbContext.SaveChanges(); return(RedirectToAction("CategoryPage", new { categoryid = newAssociation.CategoryId })); }
public IActionResult CategoryPage(int categoryid) { CategoryAndProductsViewModel ViewModel = new CategoryAndProductsViewModel() { TheCategory = dbContext.Categories.Where(c => c.CategoryId == categoryid).Include(c => c.Products).ThenInclude(c => c.Product).FirstOrDefault(), NonassociatedProducts = dbContext.Products.Where(p => p.Categories.All(c => c.CategoryId != categoryid)).ToList() }; return(View(ViewModel)); }