Exemplo n.º 1
0
        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));
        }
Exemplo n.º 2
0
 public IActionResult AddProduct(AssocProdToCatViewModel model)
 {
     dbContext.Add(model.Association);
     dbContext.SaveChanges();
     return(Redirect($"category/{model.Association.CategoryId}"));
 }