public ActionResult Edit(int id, FormCollection collection) { var model = bll.GetSingleModel(m => m.userID == id); string pwd = model.userPasswd; this.TryUpdateModel <sys_user>(model); string ckpwd = collection.Get("ckpwd"); if (!string.IsNullOrWhiteSpace(ckpwd) && !string.IsNullOrWhiteSpace(model.userPasswd)) { pwd = Encrypt.MD5(Encrypt.Encode(model.userPasswd)); } model.userPasswd = pwd; //model.acctounName = collection.Get("acctounName"); string roleID = collection.Get("roleID"); if (model.departID == 0 || roleID == "0") { var deparList = depabll.LoadEntities(m => m.ID > 0); deparList.Insert(0, new sys_Department { DeparName = "选择部门" }); ViewBag.departIDs = new SelectList(deparList, "ID", "DeparName"); //部门 var roleList = roleBll.LoadEntities(m => m.groupID > 0); roleList.Insert(0, new sys_group { groupName = "选择角色" }); ViewBag.roleIDs = new SelectList(roleList, "groupID", "groupName");//角色 ViewBag.departErro = "请选择部门"; ViewBag.roleIDsErro = "请选择角色"; return(View("Edit", model)); } try { using (TransactionScope scope = new TransactionScope()) { bll.UpdateEntities(model); sys_group_user roles = gropbll.GetSingleModel(m => m.userID == model.userID); roles.groupID = int.Parse(roleID); gropbll.UpdateEntities(roles); scope.Complete(); } return(this.JscriptMsg("信息已添加成功", false, "Success")); } catch { return(this.JscriptMsg("信息已添加失败", false, "Error")); } }
public ActionResult Add(FormCollection collection) { var model = new sys_user(); this.TryUpdateModel <sys_user>(model); string pwd = Encrypt.MD5(Encrypt.Encode(model.userPasswd)); model.userPasswd = pwd; string roleID = collection.Get("roleID"); if (model.departID == 0 || roleID == "0") { var deparList = depabll.LoadEntities(m => m.ID > 0); deparList.Insert(0, new sys_Department { DeparName = "选择部门" }); ViewBag.departIDs = new SelectList(deparList, "ID", "DeparName"); //部门 var roleList = roleBll.LoadEntities(m => m.groupID > 0); roleList.Insert(0, new sys_group { groupName = "选择角色" }); ViewBag.roleIDs = new SelectList(roleList, "groupID", "groupName");//角色 ViewBag.departErro = "请选择部门"; ViewBag.roleIDsErro = "请选择角色"; return(View("Edit")); } try { using (TransactionScope scope = new TransactionScope()) { object ids = bll.AddEntities(model); sys_group_user roles = new sys_group_user(); roles.groupID = int.Parse(roleID); roles.userID = int.Parse(ids.ToString()); gropbll.AddEntities(roles); scope.Complete(); } return(this.JscriptMsg("信息已添加成功", false, "Success")); } catch { return(this.JscriptMsg("信息已添加失败", false, "Error")); } }