public ActionResult Edit(Product product) { if (ModelState.IsValid) { HttpPostedFileBase photo = Request.Files["productImg"]; string strImage = SaveProductPhoto(photo, product.product_id); if (!string.IsNullOrEmpty(strImage)) product.product_image = strImage; db.Products.Attach(product); db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return RedirectToAction("Index"); } ViewBag.product_type_id = new SelectList(db.Ref_Product_Type, "product_type_id", "product_type_description_vn", product.product_type_id); ViewBag.product_uom_id = new SelectList(db.Unit_Of_Measure, "UOM_id", "UOM_description", product.product_uom_id); return View(product); }
public ActionResult Create(Product product) { if (ModelState.IsValid) { try { HttpPostedFileBase photo = Request.Files["productImg"]; product.product_image = SaveProductPhoto(photo); product.product_created_date = DateTime.Now; db.Products.Add(product); db.SaveChanges(); } catch (Exception ex) { throw ex; } return RedirectToAction("Index"); } ViewBag.product_type_id = new SelectList(db.Ref_Product_Type, "product_type_id", "product_type_description_vn", product.product_type_id); ViewBag.product_uom_id = new SelectList(db.Unit_Of_Measure, "UOM_id", "UOM_description", product.product_uom_id); return View(product); }