public ActionResult AddProduct(TBLPRODUCTS p1) { var ctgr = db.TBLCATEGORIES.Where(m => m.CATEGORYID == p1.TBLCATEGORIES.CATEGORYID).FirstOrDefault(); p1.TBLCATEGORIES = ctgr; db.TBLPRODUCTS.Add(p1); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult UPDATE(TBLPRODUCTS p) { var product = db.TBLPRODUCTS.Find(p.PRODUCTID); product.PRODUCTNAME = p.PRODUCTNAME; product.BRAND = p.BRAND; product.STOCK = p.STOCK; product.PRICE = p.PRICE; //product.PRODUCTCATEGORY = p.PRODUCTCATEGORY; var ctgr = db.TBLCATEGORIES.Where(m => m.CATEGORYID == p.TBLCATEGORIES.CATEGORYID).FirstOrDefault(); product.PRODUCTCATEGORY = ctgr.CATEGORYID; db.SaveChanges(); return(RedirectToAction("Index")); }