public ActionResult Edit(int id) { VM_BoxGood_Form1 m = new VM_BoxGood_Form1(); using (var db = new box_omsEntities()) { var dbm = db.box_good.Find(id); m.id = dbm.BoxId; m.State = dbm.State; m.Prov = Convert.ToInt32(dbm.Prov); m.City = Convert.ToInt32(dbm.City); m.Area = Convert.ToInt32(dbm.Area); m.UseUserName = dbm.UseUserName; m.SchoolName = dbm.SchoolName; m.Chinese = BoxOms.Web.BLL.BoxGoodBLL.BackEditionid(dbm.BoxId, 1); m.Math = BoxOms.Web.BLL.BoxGoodBLL.BackEditionid(dbm.BoxId, 2); m.English = BoxOms.Web.BLL.BoxGoodBLL.BackEditionid(dbm.BoxId, 3); } return(View(m)); }
public ActionResult Edit(VM_BoxGood_Form1 m) { if (ModelState.IsValid) { if (m.UseUserName.Length > 10) { ModelState.AddModelError("UseUserName", "输入的字符不能超过10个!"); return(View(m)); } if (m.SchoolName.Length > 20) { ModelState.AddModelError("SchoolName", "输入的字符不能超过20个!"); return(View(m)); } using (var db = new box_omsEntities()) { box_good dbm = db.box_good.Find(m.id); dbm.UpdateTime = DateTime.Now; dbm.UpdateUserId = System.Web.HttpContext.Current.Session["UserInfo"] == null ? 0 : (System.Web.HttpContext.Current.Session["UserInfo"] as VM_SyPassport_UserInfo).Id; dbm.State = m.State; dbm.Prov = m.Prov.ToString(); dbm.City = m.City.ToString(); dbm.Area = m.Area.ToString(); dbm.UseUserName = m.UseUserName; dbm.SchoolName = m.SchoolName; //先删除然后重新添加 db.box_subject_edition.RemoveRange(db.box_subject_edition.Where(_ => _.BoxId == m.id)); Bind(m.English, db, dbm.BoxId, 3); Bind(m.Math, db, dbm.BoxId, 2); Bind(m.Chinese, db, dbm.BoxId, 1); db.SaveChanges(); return(Json(new { success = true })); } } return(View(m)); }