/// <summary> /// 清除用户归属的角色 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <returns>影响行数</returns> public int ClearUserRole(BaseUserInfo userInfo, string userId) { var result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); result = userManager.ClearRole(userInfo.SystemCode, userId); }); return(result); }
/// <summary> /// 批量设置用户的角色 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <param name="roleIds">角色数组</param> /// <returns>影响的行数</returns> public int SetUserRoles(BaseUserInfo userInfo, string userId, string[] roleIds) { var result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var userManager = new BaseUserManager(dbHelper, userInfo); // 小心异常,检查一下参数的有效性 if (roleIds != null) { userManager.ClearRole(userInfo.SystemCode, userId); result += userManager.AddToRole(userInfo.SystemCode, new string[] { userId.ToString() }, roleIds); } }); return(result); }
/// <summary> /// 清除用户归属的角色 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <returns>影响行数</returns> public int ClearUserRole(BaseUserInfo userInfo, string userId) { // 写入调试信息 #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); BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo); returnValue = userManager.ClearRole(userId); BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, MethodBase.GetCurrentMethod()); } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } // 写入调试信息 #if (DEBUG) BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart); #endif return(returnValue); }
/// <summary> /// 清除用户权限 /// /// 1.清除用户的角色归属。 /// 2.清除用户的模块权限。 /// 3.清除用户的操作权限。 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <returns>数据表</returns> public int ClearUserPermission(BaseUserInfo userInfo, string userId) { var result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (ServiceUtil.ProcessFun)((dbHelper) => { var systemCode = userInfo.SystemCode; var userManager = new BaseUserManager(dbHelper, userInfo); result += userManager.ClearRole(systemCode, userId); var userPermissionManager = new BasePermissionManager((IDbHelper)dbHelper, (BaseUserInfo)userInfo); result += userPermissionManager.RevokeUserAll(systemCode, userId); var userPermissionScopeManager = new BaseUserScopeManager(dbHelper, userInfo); result += userPermissionScopeManager.RevokeAll(systemCode, userId); })); return(result); }