public ActionResult Create(ProductPropertyManageCreateViewModel model) { if (ModelState.IsValid) { var productProperty = new ProductProperty { Name = model.Name, Description = model.Description, PlusPrice=model.PlusPrice }; db.ProductProperties.Add(productProperty); db.SaveChanges(); 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); productProperty.ImgUrl = pathRel; db.Entry(productProperty).State = EntityState.Modified; db.SaveChanges(); } return RedirectToAction("Index"); } return View(model); }
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); }