public JsonResult Create(FormCollection col) { try { Guid userid = Tool.String2Guid(col["userid"]); SYS_USER model = new SYS_USER(); if (userid == Guid.Empty) { model.USERID = Guid.NewGuid(); model.OPERATEDATE = DateTime.Now; model.ISDELETED = 0; FillModel(ref model, col); string pwd = Tool.GetMD5Hash(Tool.textToBytes(col["PASSWORD"])); model.PASSWORD = pwd; DbContext.SYS_USER.Add(model); } else { model = DbContext.SYS_USER.FirstOrDefault(m => m.USERID == userid); FillModel(ref model, col); DbContext.Entry(model).State = System.Data.EntityState.Modified; } DbContext.SaveChanges(); return new JsonM().ToJson(true, MsgHelper.SaveSuccess); } catch (Exception ex) { return new JsonM().ToJson(false, MsgHelper.SaveFail, ex.Message); } }
public ActionResult Create(string q_userid = "") { ViewData["Area"] = base.AreaListOptions; SYS_USER model; if (string.IsNullOrEmpty(q_userid)) { model = new SYS_USER(); } else { Guid g = Tool.String2Guid(q_userid); model = DbContext.SYS_USER.FirstOrDefault(m => m.USERID == g); } return View(model); }
private void FillModel(ref SYS_USER model, FormCollection col) { model.USERNAME = col["USERNAME"]; model.FULLNAME = col["FULLNAME"]; model.SHORTNAME = col["SHORTNAME"]; model.DEPTNAME = col["DEPTNAME"]; model.ALLOWLOGIN = col["ALLOWLOGIN"]; model.SEQUENCE = Tool.String2Int32(col["SEQUENCE"]); model.QQ = col["QQ"]; model.MOBILE = col["MOBILE"]; model.AREAID = Tool.String2Guid2(col["AREAID"]); model.AREANAME = col["AREANAME"]; model.REMARK = col["REMARK"]; }