public ActionResult CreateProduct(Product pro, HttpPostedFileBase fPmain, HttpPostedFileBase fPmainthums) { pro.TinyDes = pro.TinyDes == null ? string.Empty : pro.TinyDes; pro.FullDes = pro.FullDes == null ? string.Empty : pro.FullDes; string spDirPath = Server.MapPath("~/Images/Imgs/sp"); using (var db = new QLBHEntities()) { db.Products.Add(pro); db.SaveChanges(); } ServiceUpload.UploadImage(spDirPath, pro.ProID, fPmain, fPmainthums); return(RedirectToAction("GetProduct", new { id = pro.CatID })); }
public ActionResult UpdateProduct(Product pro, HttpPostedFileBase fPmain, HttpPostedFileBase fPmainthums) { using (var DB = new QLBHEntities()) { Product proEdit = DB.Products.Where(item => item.ProID == pro.ProID) .FirstOrDefault(); if (proEdit != null) { string spDirPath = Server.MapPath("~/Images/Imgs/sp"); ServiceUpload.UploadImage(spDirPath, pro.ProID, fPmain, fPmainthums); proEdit.ProName = pro.ProName; proEdit.Quantity = pro.Quantity; proEdit.Price = pro.Price; proEdit.TinyDes = pro.TinyDes; proEdit.FullDes += pro.FullDes; DB.SaveChanges(); DB.Entry(proEdit).State = EntityState.Modified; } ViewBag.Cat = DB.Categories.ToList(); return(RedirectToAction("GetProduct", new { id = proEdit.CatID })); } }