public ActionResult Create(AddPro addPro) { var picture = upload(addPro.Picture); var CLIENT_ID = System.Configuration.ConfigurationManager.AppSettings["Imgur_CLIENT_ID"]; var CLIENT_SECRET = System.Configuration.ConfigurationManager.AppSettings["Imgur_CLIENT_SECRET"]; if (ModelState.IsValid) { Product p = new Product(); p.ProductName = addPro.PName; p.SupplierID = addPro.SupplierID; p.CategoryID = addPro.CategoryID; p.UnitPrice = addPro.PPrice; p.Picture = picture; p.Description = addPro.Pdescript; p.Quantity = addPro.PQuantity; p.SalesPrice = addPro.PSalesPrice; p.Status = "未上架"; db.Products.Add(p); db.SaveChanges(); return(RedirectToAction("Index", "Products")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", addPro.CategoryID); ViewBag.SupplierID = new SelectList(db.Suppliers, "SupplierID", "CompanyName", addPro.SupplierID); return(View(addPro)); }
public ActionResult Edit(AddPro addPro) { if (ModelState.IsValid) { Product p = new Product(); Category c = new Category(); p.ProductName = addPro.PName; p.SupplierID = addPro.SupplierID; p.CategoryID = addPro.CategoryID; p.UnitPrice = addPro.PPrice; p.Description = addPro.Pdescript; p.Quantity = addPro.PQuantity; p.SalesPrice = addPro.PSalesPrice; db.Entry(p).State = EntityState.Modified; db.Entry(c).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(addPro)); }