Пример #1
0
 public ActionResult Edit(Category category)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId);
     return(View(product));
 }
Пример #3
0
 public ActionResult Edit(Product product)
 {
     if (ModelState.IsValid)
     {
         if (Request.Files.Count > 0 && Request.Files[0] != null)
         {
             string filePath = Path.Combine(HttpContext.Server.MapPath("~/Content/ProductImages"),
                                            Path.GetFileName(Request.Files[0].FileName));
             Request.Files[0].SaveAs(filePath);
             product.ProductImageUrl = filePath;
         }
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.CategoryId = new SelectList(db.Categories, "CategoryId", "Name", product.CategoryId);
     return(View(product));
 }