public ActionResult Edit(ProductPropertyManageEditViewModel model) { if (ModelState.IsValid) { string newPropertymgUrl; if (model.PropertyImg != null) { var uploadedFile = new UploadedFile(model.PropertyImg); var propertyImgName = uploadedFile.SaveAs(Server.MapPath("~/ImgRepository/ProductPropertyImgs/")); var pathRel = Url.Content("~/ImgRepository/ProductPropertyImgs/" + propertyImgName); newPropertymgUrl = pathRel; } else { newPropertymgUrl = db.Products.Find(model.Id).CoverImgUrl; } var productProperty = new ProductProperty { Id=model.Id, Name=model.Name, Description=model.Description, ImgUrl= newPropertymgUrl, PlusPrice=model.PlusPrice }; db.Entry(productProperty).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } return View(model); }
// GET: ProductPropertyManage/Edit/5 public ActionResult Edit(int? id) { if (id == null) { return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } ProductProperty productProperty = db.ProductProperties.Find(id); if (productProperty == null) { return HttpNotFound(); } var vm = new ProductPropertyManageEditViewModel { Id=productProperty.Id, Name=productProperty.Name, Description=productProperty.Description, ImgUrl=productProperty.ImgUrl, PlusPrice=productProperty.PlusPrice }; return View(vm); }