public IActionResult ProductPage(int productid) { ProductAndCategoriesViewModel ViewModel = new ProductAndCategoriesViewModel() { TheProduct = dbContext.Products.Where(p => p.ProductId == productid).Include(p => p.Categories).ThenInclude(p => p.Category).FirstOrDefault(), NonAssociatedCategories = dbContext.Categories.Where(c => c.Products.All(p => p.ProductId != productid)).ToList() }; return(View(ViewModel)); }
public IActionResult AddCategory(ProductAndCategoriesViewModel modelData) { Association newAssociation = modelData.NewAssociation; Console.WriteLine("**********************HELLO**************************"); Console.WriteLine(ModelState.ErrorCount); Console.WriteLine(JsonConvert.SerializeObject(ModelState.Keys)); Console.WriteLine(JsonConvert.SerializeObject(ModelState.Values)); Console.WriteLine(ModelState.ValidationState); dbContext.Add(newAssociation); dbContext.SaveChanges(); return(RedirectToAction("ProductPage", new { productid = newAssociation.ProductId })); }