Пример #1
0
        private categoryAssociationInfo categoryInfo(int category_id)
        {
            var modelInfo = new categoryAssociationInfo();

            modelInfo.category = dbContext.Categories.Include(c => c.products)
                                 .ThenInclude(p => p.product)
                                 .FirstOrDefault(c => c.category_id == category_id);

            modelInfo.allProducts = dbContext.Products.Include(p => p.categories)
                                    .Where(p => p.categories.All(c => c.category_id != category_id))
                                    .ToList();
            return(modelInfo);
        }
Пример #2
0
        public IActionResult allProduct(categoryAssociationInfo associationInfo)
        {
            if (ModelState.IsValid)
            {
                dbContext.Associations.Add(associationInfo.association);
                dbContext.SaveChanges();
                return(RedirectToAction("Category", new{ category_id = associationInfo.association.category_id }));
            }


            var modelInfo = productInfo(associationInfo.association.category_id);

            return(View("Category", modelInfo));
        }