Esempio n. 1
0
        public IActionResult ShowProduct(int ProductId)
        {
            AssocCattoProdViewModel model = new AssocCattoProdViewModel()
            {
                Product = dbContext.Products
                          .Include(prod => prod.Associations)
                          .ThenInclude(assoc => assoc.Category)
                          .FirstOrDefault(prod => prod.ProductId == ProductId),

                Categories = dbContext.Categorys.Where(c => c.Associations.All(a => a.ProductId != ProductId))
                             .ToList()
            };

            return(View(model));
        }
Esempio n. 2
0
 public IActionResult AddCategory(AssocCattoProdViewModel model)
 {
     dbContext.Add(model.Association);
     dbContext.SaveChanges();
     return(Redirect($"products/{model.Association.ProductId}"));
 }