コード例 #1
0
 public ActionResult Edit([Bind(Include = "id,name,address,phone,email,department_id")] Employee employee)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employee).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employee));
 }
コード例 #2
0
 public ActionResult Edit([Bind(Include = "id,description,price,discount,category_id,image,sort_id,status")] Product product, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         db.Entry(product).State = EntityState.Modified;
         db.SaveChanges();
         if (file != null && file.ContentLength > 0)
         {
             string path = Path.Combine(Server.MapPath("~/Content/Images/"), product.image);
             file.SaveAs(path);
         }
         return(RedirectToAction("Index"));
     }
     ViewBag.category_id = new SelectList(db.Categories, "id", "name", product.category_id);
     return(View(product));
 }
コード例 #3
0
 public ActionResult Edit([Bind(Include = "id,name,image,parent_id,sort_id,status")] Category category, HttpPostedFileBase file)
 {
     if (ModelState.IsValid)
     {
         db.Entry(category).State = EntityState.Modified;
         db.SaveChanges();
         //Luu hinh san pham vao folder category
         if (file != null && file.ContentLength > 0)
         {
             string path = Path.Combine(Server.MapPath("~/Content/Images/"), category.image);
             file.SaveAs(path);
         }
         return(RedirectToAction("Index"));
     }
     return(View(category));
 }