public IActionResult ShowProduct(int ProductId) { Product retrivedProduct = dbContext.Product.Include(p => p.AssociationCategory).ThenInclude(Category => Category.Category).FirstOrDefault(Product => Product.ProductId == ProductId); ViewBag.oneProduct = retrivedProduct; List <Category> noCategories = dbContext.Category.Include(p => p.Associations).ThenInclude(a => a.Product).ToList(); List <Category> _currentCategories = new List <Category>(); foreach (var one in noCategories) { if (!one.Associations.Any(c => c.Product == retrivedProduct)) { _currentCategories.Add(one); } } ViewBag.currentCategories = _currentCategories; NewProductCategoryModel newView = new NewProductCategoryModel(); newView.newProduct = retrivedProduct; return(View(newView)); }
public IActionResult Index() { List <Product> AllProducts = dbContext.Product.ToList(); ViewBag.AllProducts = AllProducts; NewProductCategoryModel viewmodel = new NewProductCategoryModel(); viewmodel.Productss = AllProducts; return(View(viewmodel)); }