//编辑用户 public ActionResult EditUser() { int userID = Convert.ToInt32(Request.Form["ID"]); DictUser user = DictUserService.LoadEntities(u => u.ID == userID).First(); user.UID = Request.Form["UID"]; user.UName = Request.Form["UName"]; if (Request.Form["Upwd"] != "" && Request.Form["Upwd"] != null) { user.Upwd = Common.ContextCode.MD5Encryption(Request.Form["Upwd"]); } user.Remark = Request.Form["Remark"]; user.ModifiedTime = DateTime.Now; user.DictRole.Clear(); string[] roleIDArray = Request.Form["DictRole"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < roleIDArray.Length; i++) { int roleId = Convert.ToInt32(roleIDArray[i]); user.DictRole.Add(DictRoleService.LoadEntities(r => r.ID == roleId).First()); } if (Request.Form["DetailTrue"].Length != 0) { DictUserInfo userInfo = null; if (user.DictUserInfo == null) { userInfo = new DictUserInfo(); DictUserInfoService.AddEntity(userInfo); user.DictUserInfo = userInfo; } else { userInfo = user.DictUserInfo; } userInfo.Birthday = Convert.ToDateTime(Request.Form["Birthday"]); userInfo.DictEducationID = Convert.ToInt32(Request.Form["DictEducationID"]); userInfo.EntryTime = Convert.ToDateTime(Request.Form["EntryTime"]); userInfo.IdentityCard = Request.Form["IdentityCard"]; userInfo.NativePlace = Request.Form["NativePlace"]; userInfo.Salary = Convert.ToDecimal(Request.Form["Salary"]); userInfo.Sex = Request.Form["Sex"]; userInfo.Tel = Request.Form["Tel"]; } int affectRow = DictUserService.SaveChange(); if (affectRow != 0) { return(Content("1")); } else { return(Content("0#用户信息更新失败!")); } }
//获取修改用户信息 public ActionResult UserLoad(int id) { DictUser user = DictUserService.LoadEntities(u => u.ID == id).FirstOrDefault(); if (user.DictUserInfo == null) { return(Content(JsonConvert.SerializeObject(new { ID = user.ID, UID = user.UID, UName = user.UName, Remark = user.Remark, DictRole = string.Join(",", user.DictRole.Select(r => r.ID.ToString()).ToArray()) }, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }))); } else { return(Content(JsonConvert.SerializeObject(new { ID = user.ID, UID = user.UID, UName = user.UName, Remark = user.Remark, EntryTime = user.DictUserInfo.EntryTime, IdentityCard = user.DictUserInfo.IdentityCard, Sex = user.DictUserInfo.Sex, Birthday = user.DictUserInfo.Birthday, DictEducationID = user.DictUserInfo.DictEducationID, Tel = user.DictUserInfo.Tel, Salary = user.DictUserInfo.Salary, NativePlace = user.DictUserInfo.NativePlace, DictRole = string.Join(",", user.DictRole.Select(r => r.ID.ToString()).ToArray()) }, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }))); } }
public ActionResult Verify(string content, string data) { bool isSuccessVerify = false; switch (content) { case "UID": default: DictUser user = DictUserService.LoadEntities(u => u.UID == data).FirstOrDefault(); isSuccessVerify = user == null; break; } //验证成功1,会转为为true; if (isSuccessVerify) { return(Content("1")); } else { return(Content("")); } }