Ejemplo n.º 1
0
        /// <summary>
        /// 撤消角色的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="revokePermissionId">撤消权限数组</param>
        /// <returns>影响的行数</returns>
        public int RevokeRolePermissionById(BaseUserInfo userInfo, string roleId, string revokePermissionId)
        {
            var result = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var manager = new BasePermissionManager(dbHelper, userInfo);
                // 小心异常,检查一下参数的有效性
                if (revokePermissionId != null)
                {
                    result += manager.RevokeRole(userInfo.SystemCode, roleId, revokePermissionId);
                }
            });

            return(result);
        }
        /// <summary>
        /// 撤销角色权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleName">角色名</param>
        /// <param name="permissionCode">权限编号</param>
        /// <returns>主键</returns>
        public int RevokeRolePermission(BaseUserInfo userInfo, string roleName, string permissionCode)
        {
            var result = 0;

            var parameter = ServiceInfo.Create(userInfo, MethodBase.GetCurrentMethod());

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                var roleId       = BaseRoleManager.GetIdByNameByCache(userInfo.SystemCode, roleName);
                var permissionId = new BaseModuleManager().GetIdByCodeByCache(userInfo.SystemCode, permissionCode);
                if (!string.IsNullOrEmpty(roleId) && !string.IsNullOrEmpty(permissionId))
                {
                    var rolePermissionManager = new BasePermissionManager(dbHelper, userInfo);
                    result = rolePermissionManager.RevokeRole(userInfo.SystemCode, roleId, permissionId);
                }
            });

            return(result);
        }