public ActionResult Create([Bind(Include = "pId,typeId,pName,pDetail,pPrice,pImage,pTexture,XS,S,M,L,XL,Date")] Inventory products, HttpPostedFileBase productImg, HttpPostedFileBase textureImg) { if (ModelState.IsValid) { string productImage = System.IO.Path.GetFileName(productImg.FileName); string productImgPath = Server.MapPath("~/ProductImages/" + productImage); productImg.SaveAs(productImgPath); string textureImage = System.IO.Path.GetFileName(textureImg.FileName); string textureImgPath = Server.MapPath("~/TextureImages/" + textureImage); textureImg.SaveAs(textureImgPath); Inventory addFotUpdate = new Inventory(); addFotUpdate.pId = products.pId; addFotUpdate.typeId = products.typeId; addFotUpdate.pName = products.pName; addFotUpdate.pDetail = products.pDetail; addFotUpdate.pPrice = products.pPrice; addFotUpdate.pImage = productImage; addFotUpdate.pTexture = textureImage; addFotUpdate.XS = products.XS; addFotUpdate.S = products.S; addFotUpdate.M = products.M; addFotUpdate.L = products.L; addFotUpdate.XL = products.XL; addFotUpdate.Date = DateTime.Now; db.Products.Add(addFotUpdate); db.SaveChanges(); PurchaseHistory addForShow = new PurchaseHistory(); addForShow.typeId = products.typeId; addForShow.pName = products.pName; addForShow.pDetail = products.pDetail; addForShow.pPrice = products.pPrice; addForShow.pImage = productImage; addForShow.pTexture = textureImage; addForShow.XS = products.XS; addForShow.S = products.S; addForShow.M = products.M; addForShow.L = products.L; addForShow.XL = products.XL; addForShow.Date = DateTime.Now; db.ProductStores.Add(addForShow); db.SaveChanges(); return RedirectToAction("Index"); } return View(products); }
public ActionResult Edit([Bind(Include = "pId,typeId,pName,pDetail,pPrice,pImage,pTexture,XS,S,M,L,XL,Date")] Inventory products) { if (ModelState.IsValid) { Inventory editForUpdate = new Inventory(); editForUpdate.pId = products.pId; editForUpdate.typeId = products.typeId; editForUpdate.pName = products.pName; editForUpdate.pDetail = products.pDetail; editForUpdate.pPrice = products.pPrice; editForUpdate.pImage = products.pImage; editForUpdate.pTexture = products.pTexture; editForUpdate.XS = products.XS; editForUpdate.S = products.S; editForUpdate.M = products.M; editForUpdate.L = products.L; editForUpdate.XL = products.XL; editForUpdate.Date = products.Date; db.Entry(editForUpdate).State = EntityState.Modified; db.SaveChanges(); PurchaseHistory editForShow = new PurchaseHistory(); editForShow.pId = products.pId; editForShow.typeId = products.typeId; editForShow.pName = products.pName; editForShow.pDetail = products.pDetail; editForShow.pPrice = products.pPrice; editForShow.pImage = products.pImage; editForShow.pTexture = products.pTexture; editForShow.XS = products.XS; editForShow.S = products.S; editForShow.M = products.M; editForShow.L = products.L; editForShow.XL = products.XL; editForShow.Date = products.Date; db.Entry(editForShow).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(products); }