public IActionResult ShowCategory(int CategoryId) { AssocProdToCatViewModel model = new AssocProdToCatViewModel() { Category = dbContext.Categorys .Include(cat => cat.Associations) .ThenInclude(assoc => assoc.Product) .FirstOrDefault(cat => cat.CategoryId == CategoryId), Products = dbContext.Products.Where(p => p.Associations.All(a => a.CategoryId != CategoryId)) .ToList() }; return(View(model)); }
public IActionResult AddProduct(AssocProdToCatViewModel model) { dbContext.Add(model.Association); dbContext.SaveChanges(); return(Redirect($"category/{model.Association.CategoryId}")); }