public ActionResult Edit([Bind(Include = "ID,Name,Description,Is_Delete,Category_ID")] Product product, Photo photoModel, HttpPostedFileBase file, int id) { if (ModelState.IsValid) { string folderPath = Server.MapPath("~/Images/"); string fileName = Path.GetFileName(file.FileName); //Check whether Directory (Folder) exists. if (!Directory.Exists(folderPath)) { //If Directory (Folder) does not exists. Create it. Directory.CreateDirectory(folderPath); } photoModel.PhotoName = "/Images/" + fileName; file.SaveAs(folderPath + fileName); photoModel.Product_ID = product.ID; db.Entry(photoModel).State = EntityState.Modified; db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Category_ID = new SelectList(db.Categories, "ID", "Name", product.Category_ID); ViewBag.ID = new SelectList(db.Photos, "ID", "PhotoName"); return(View(product)); }
public ActionResult Edit([Bind(Include = "ID,Username,Password,Fullname,Email,DateOfBirth,Phone,Address,Is_Delete,Role_ID,Avatar")] User user) { if (ModelState.IsValid) { db.Entry(user).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Role_ID = new SelectList(db.Roles, "ID", "Name", user.Role_ID); return(View(user)); }
public ActionResult Edit([Bind(Include = "ID,Product_ID,Origin,Remain,Product_Date")] Quantity quantity) { if (ModelState.IsValid) { db.Entry(quantity).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.Product_ID = new SelectList(db.Products, "ID", "Name", quantity.Product_ID); return(View(quantity)); }