/// <summary> /// 用户分配角色 /// </summary> /// <param name="userId"></param> /// <param name="roleId"></param> /// <returns></returns> public JsonMessage AllotSysUserRole(string userId, string roleId) { JsonMessage jsonMsg = new JsonMessage(); //返回Json int result = -1; //类型(成功 、失败) _userRep.BeginTransaction(); try { _userRep.DeleteSysUserRoleByUserId(userId); string[] roleIds = roleId.Split(','); for (int i = 0; i < roleIds.Length; i++) { SysUserRoleModel model = new SysUserRoleModel(); model.USER_CODE = userId; model.ROLE_ID = roleIds[i]; model.CREATE_USER = UserID; model.LM_USER = UserID; result = _userRep.AllotSysUserRole(model); } _userRep.CommitTransaction(); jsonMsg = ServiceResult.Message(result, "操作成功"); } catch (Exception ex) { _userRep.RollbackTransaction(); jsonMsg = ServiceResult.Message(-1, ex.Message); WriteSystemException(ex, this.GetType(), OPT_MODEL, "用户分配角色失败"); } //写入log WriteSystemLog(jsonMsg, CREATE, OPT_MODEL, "用户分配角色"); return(jsonMsg); }
public virtual bool Create(SysUserRoleModel model) { try { tbl_SysUserRole entity = m_Rep.GetById(model.Id); if (entity != null) { return(false); } entity = new tbl_SysUserRole(); entity.Id = model.Id; entity.UserId = model.UserId; entity.RoleId = model.RoleId; if (m_Rep.Create(entity)) { return(true); } else { return(false); } } catch (Exception ex) { return(false); } }
/// <summary> /// 根据ID获取角色信息 /// </summary> /// <param name="RoleId"></param> public void GetRole(long RoleId) { try { this.UserRole = BaseSysTemDataBaseManager.SysGetSysRoleById(RoleId); } catch (Exception e) { SysSaveErrorLogMsg(e.ToString(), RoleId); } }
public virtual SysUserRoleModel GetById(string id) { if (IsExists(id)) { tbl_SysUserRole entity = m_Rep.GetById(id); SysUserRoleModel model = new SysUserRoleModel(); model.Id = entity.Id; model.UserId = entity.UserId; model.RoleId = entity.RoleId; return(model); } else { return(null); } }
public ReplayBase EditSysRole(SysUserRoleModel SysRole) { SysManagerService sms = new SysManagerService(); sms.UserRole = SysRole; ReplayBase result = sms.SaveRole(); if (result.ReturnCode == EnumErrorCode.Success) { SysUserLogModel log = new SysUserLogModel() { Describe = "添加/编辑角色:" + SysRole.RoleName, SysUserId = User.Identity.Name }; SysManagerService.CreateSysUserLog(log); } return(result); }
/// <summary> /// 分配用户角色 /// </summary> /// <param name="model"></param> /// <returns></returns> public int AllotSysUserRole(SysUserRoleModel model) { StringBuilder sql = new StringBuilder(); sql.AppendLine("INSERT INTO SYS_USER_ROLE"); sql.AppendLine(" (USER_CODE, ROLE_ID, CREATE_USER, LM_USER)"); sql.AppendLine("VALUES"); sql.AppendLine(" ($USER_CODE, $ROLE_ID, $CREATE_USER, $LM_USER)"); SQLParameter[] parms = { new SQLParameter("USER_CODE", typeof(string), model.USER_CODE), new SQLParameter("ROLE_ID", typeof(string), model.ROLE_ID), new SQLParameter("CREATE_USER", typeof(string), model.CREATE_USER), new SQLParameter("LM_USER", typeof(string), model.LM_USER) }; int result = DB.CustomExecuteWithReturn(new SQLParamCondition(sql.ToString(), parms)); return(result); }
/// <summary> /// 新增或更改角色的用户 /// </summary> /// <param name="userList"></param> /// <param name="roleId"></param> /// <param name="len"></param> /// <returns></returns> public string CreateUserRole(List <SysUserModel> userList, string roleId, int len) { List <SysUserRoleModel> list = userRoleBLL.GetByRoleId(roleId); //去除已有的不需更改的记录 for (int i = 0; i < len; i++) { for (int j = 0; j < list.Count; j++) { if (userList[i].UserId == list[j].UserId) { userList.Remove(userList[i]); list.Remove(list[j]); i--; len--; break; } } if (userList.Count == 0) { break; } } if (list.Count != 0) { foreach (var a in list) { if (!userRoleBLL.Delete(a.Id)) { var json = js.Serialize(new { flag = false }); return(json); } } } if (userList.Count != 0) { foreach (var a in userList) { SysUserRoleModel userRoleModel = new SysUserRoleModel(); userRoleModel.Id = ResultHelper.NewId; userRoleModel.UserId = a.UserId; userRoleModel.RoleId = roleId; if (!userRoleBLL.Create(userRoleModel)) { var json = js.Serialize(new { flag = false }); return(json); } } var jsondata = js.Serialize(new { flag = true }); return(jsondata); } else if (list.Count == 0) { var jsondata = js.Serialize(new { flag = false }); return(jsondata); } else { var jsondata = js.Serialize(new { flag = true }); return(jsondata); } }