public ActionResult EditProducts(tblProduct productModel, HttpPostedFileBase fileUpload) { if (ModelState.IsValid) { string pictureLink = ""; if (fileUpload != null) { Image img = Image.FromStream(fileUpload.InputStream); int width = Convert.ToInt32(ConfigurationManager.AppSettings["ProductWidth"].ToString()); int height = Convert.ToInt32(ConfigurationManager.AppSettings["ProductHeight"].ToString()); pictureLink = "/img/ProductsImage/" + Guid.NewGuid() + Path.GetExtension(fileUpload.FileName); Bitmap bm = new Bitmap(img, width, height); bm.Save(Server.MapPath(pictureLink)); } if (pictureLink == "") { productModel.PictureLink = "/img/ProductsImage/emptyProducts.jpg"; } else { productModel.PictureLink = pictureLink; } db.Entry(productModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Products")); } ViewBag.CategoryId = new SelectList(db.tblCategory, "Id", "Name", productModel.CategoryId); return(View(productModel)); }
public ActionResult EditAccount(tblUsers userModel) { if (ModelState.IsValid) { db.Entry(userModel).State = EntityState.Modified; db.SaveChanges(); return(View()); } return(View(userModel)); }