/// <summary> /// 将用户从角色中移除 /// </summary> /// <param name="userInfo">用户</param> /// <param name="roleId">角色主键</param> /// <param name="userIds">用户主键</param> /// <returns>影响行数</returns> public int RemoveUserFromRole(BaseUserInfo userInfo, string roleId, string[] userIds) { // 写入调试信息 #if (DEBUG) int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod()); #endif // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); dbHelper.BeginTransaction(); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); if (userIds != null) { returnValue += userManager.RemoveFormRole(userIds, roleId); } BaseLogManager.Instance.Add(dbHelper, userInfo, serviceName, AppMessage.RoleService_RemoveUserFromRole, MethodBase.GetCurrentMethod()); dbHelper.CommitTransaction(); } catch (Exception ex) { dbHelper.RollbackTransaction(); BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return returnValue; }
/// <summary> /// 用户从角色移除 /// </summary> /// <param name="userInfo">用户</param> /// <param name="roleName">角色名</param> /// <param name="permissionItemCode">权限编号</param> /// <returns>主键</returns> public int RemoveUserFromRole(BaseUserInfo userInfo, string userName, string roleName) { // 加强安全验证防止未授权匿名调用 #if (!DEBUG) LogOnService.UserIsLogOn(userInfo); #endif int returnValue = 0; using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType)) { try { dbHelper.Open(UserCenterDbConnection); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); string userId = userManager.GetId(new KeyValuePair<string, object>(BaseUserEntity.FieldUserName, userName)); BaseRoleManager roleManager = new BaseRoleManager(dbHelper, userInfo); string roleId = roleManager.GetId(new KeyValuePair<string, object>(BaseRoleEntity.FieldRealName, roleName)); if (!String.IsNullOrEmpty(userId) && !String.IsNullOrEmpty(roleId)) { returnValue = userManager.RemoveFormRole(userId, roleId); } } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } return returnValue; }