public ActionResult add(int id, sysMenusView model) { try { //1.0 实体模型属性合法性验证 if (ModelState.IsValid == false) { SetStatus(); return(View()); } //2.0 保存数据 //2.0.1 先补齐页面没有传入的,但是DB要求不为null的数据字段值 model.mParentID = id; model.mCreateTime = DateTime.Now; model.mCreatorID = UserMgr.GetCurrentUserInfo().uID; model.mUpdateTime = DateTime.Now; //2.0.2 保存 menuSer.Add(model.EntityMap()); menuSer.SaveChanges(); return(base.WriteSuccess("数据保存成功")); } catch (Exception ex) { return(WriteError(ex.Message)); } }
public ActionResult add(int id, sysMenusView model) { try { //1.0实体属性合法性验证 if (ModelState.IsValid == false) { SetStatus(); return(View()); } //2.0保存数据 model.mParentID = id; model.mCreateTime = DateTime.Now; model.mCreatorID = UserMgr.GetCurrentUserInfo().uID; model.mUpdateTime = DateTime.Now; model.mUpdateID = UserMgr.GetCurrentUserInfo().uID; model.mExp1 = null; model.mExp2 = null; sysMenus entity = model.EntityMap(); //2.0.2 保存 _menuSer.Add(entity); _menuSer.SaveChanges(); return(base.WriteSuccess("数据保存成功")); } //catch (DbEntityValidationException dbEx) //{ // string s = null; // foreach (var validationErrors in dbEx.EntityValidationErrors) // { // foreach (var validationError in validationErrors.ValidationErrors) // { // s += string.Format("Class: {0}, Property: {1}, Error: {2}", // validationErrors.Entry.Entity.GetType().FullName, // validationError.PropertyName, // validationError.ErrorMessage); // } // } // return base.WriteError(s); //} catch (Exception ex) { return(WriteError(ex.Message)); } }