/// <summary> /// 撤销用户权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userName">用户名</param> /// <param name="permissionItemCode">权限编号</param> /// <returns>主键</returns> public int RevokeUserPermission(BaseUserInfo userInfo, string userName, string permissionItemCode) { // 加强安全验证防止未授权匿名调用 #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)); BasePermissionItemManager permissionItemManager = new BasePermissionItemManager(dbHelper, userInfo); string permissionItemId = permissionItemManager.GetId(new KeyValuePair<string, object>(BasePermissionItemEntity.FieldCode, permissionItemCode)); if (!String.IsNullOrEmpty(userId) && !String.IsNullOrEmpty(permissionItemId)) { BaseUserPermissionManager userPermissionManager = new BaseUserPermissionManager(dbHelper, userInfo); returnValue = userPermissionManager.Revoke(userId, permissionItemId); } } catch (Exception ex) { BaseExceptionManager.LogException(dbHelper, userInfo, ex); throw ex; } finally { dbHelper.Close(); } } 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; }