private productAssociationInfo productInfo(int product_id) { var modelInfo = new productAssociationInfo(); modelInfo.product = dbContext.Products.Include(p => p.categories) .ThenInclude(a => a.category) .FirstOrDefault(product => product.product_id == product_id); modelInfo.allCategory = dbContext.Categories.Include(c => c.products).ThenInclude(p => p.category) .Where(c => c.products.All(p => p.product_id != product_id)) .ToList(); return(modelInfo); }
public IActionResult addCategory(productAssociationInfo associationInfo) { if (ModelState.IsValid) { dbContext.Associations.Add(associationInfo.association); dbContext.SaveChanges(); // var newCategory=dbContext.Categories.FirstOrDefault(c=>c.category_id==associationInfo.association.category_id); // return Json(newCategory); return(RedirectToAction("Product", new{ product_id = associationInfo.association.product_id })); } var modelInfo = productInfo(associationInfo.association.product_id); return(View("Product", modelInfo)); }