public ActionResult Upload(Product product, HttpPostedFileBase file) { string path = Server.MapPath("~/Products/" + file.FileName); file.SaveAs(path); ViewBag.Path = path; return View(); }
// POST: ManageProduct/Create //[HttpPost] public ActionResult Create(Product product, HttpPostedFileBase file) { //tring path = Server.MapPath("~/Products/" + file.FileName); string ImageName = System.IO.Path.GetFileName(file.FileName); string physicalPath = Server.MapPath("~/Products/" + ImageName); product.Image = ImageName; // save image in folder file.SaveAs(physicalPath); try { // TODO: Add insert logic here if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return RedirectToAction("Index"); } PopulateTypeIdDropDownList(product.TypeId); return View(product); } catch { return View(); } }
public ActionResult Create(Product product) { try { // TODO: Add insert logic here if (ModelState.IsValid) { db.Products.Add(product); db.SaveChanges(); return RedirectToAction("Index"); } PopulateTypeIdDropDownList(product.TypeId); PopulateImageUrlDropDownList(product.Image); return View(product); } catch { return View(); } }
public ActionResult Edit(Product product) { try { // TODO: Add update logic here if (ModelState.IsValid) { db.Entry(product).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } //PopulateTypeIdDropDownList(product.TypeId); return View(product); } catch { return View(); } }
public ActionResult Delete(int? id, Product prod) { try { Product product = new Product(); // TODO: Add delete logic here if (ModelState.IsValid) { if (id == null) return new HttpStatusCodeResult(HttpStatusCode.BadRequest); product = db.Products.Find(id); if (product == null) return HttpNotFound(); db.Products.Remove(product); db.SaveChanges(); return RedirectToAction("Index"); } return View(product); } catch { return View(); } }