public JsonResult UpdateProduct(APIProduct _product) { var restResult = new RestModel(); try { product updateModel = new product(); updateModel = db.products.Find(_product.id); updateModel.cat_id = _product.cat_id; updateModel.name = _product.name; updateModel.price = _product.price; updateModel.img = _product.img; updateModel.note = _product.note; db.Entry(updateModel).State = System.Data.Entity.EntityState.Modified; db.SaveChanges(); restResult.status = true; } catch (Exception ex) { restResult.status = false; restResult.message = ex.Message; } return(Json(restResult, JsonRequestBehavior.AllowGet)); }
public JsonResult UpdateCategory(APICategory _category) { var restResult = new RestModel(); try { category updateModel = new Models.category(); updateModel = db.categories.Find(_category.id); updateModel.name = _category.name; db.Entry(updateModel).State = EntityState.Modified; db.SaveChanges(); restResult.status = true; } catch (Exception ex) { restResult.status = false; restResult.message = ex.Message; } return(Json(restResult, JsonRequestBehavior.AllowGet)); }
public ActionResult Edit([Bind(Include = "id,name,is_deleted")] category category) { if (ModelState.IsValid) { db.Entry(category).State = EntityState.Modified; // Thu: Not modified field is_deleted khi edit db.Entry(category).Property("is_deleted").IsModified = false; db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Edit([Bind(Include = "id,cat_id,name,price,img,is_deleted")] product product) { if (ModelState.IsValid) { db.Entry(product).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.cat_id = new SelectList(db.categories, "id", "name", product.cat_id); return(View(product)); }