/// <summary> /// 撤消用户操作权限 /// </summary> /// <param name="userInfo">用户</param> /// <param name="userId">用户主键</param> /// <param name="revokePermissionIds">撤消权限数组</param> /// <returns>影响的行数</returns> public int RevokeUserPermissionById(BaseUserInfo userInfo, string userId, string revokePermissionId) { int result = 0; var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod()); ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) => { var manager = new BaseUserPermissionManager(dbHelper, userInfo); // 小心异常,检查一下参数的有效性 if (revokePermissionId != null) { result += manager.Revoke(userInfo.SystemCode, userId, revokePermissionId); } }); return(result); }
/// <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); }