/// <summary>
        /// 撤销角色全部权限
        /// </summary>
        /// <param name="roleId">角色主键</param>
        /// <returns>影响行数</returns>
        public int RevokeAll(string roleId)
        {
            BasePermissionManager permissionManager          = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseRoleEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, roleId));
            return(permissionManager.Delete(parameters));
        }
        //
        //  撤销权限的实现部分
        //

        #region private int Revoke(BasePermissionManager permissionManager, string roleId, string permissionItemId) 为了提高撤销的运行速度
        /// <summary>
        /// 为了提高撤销的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>影响行数</returns>
        private int Revoke(BasePermissionManager permissionManager, string roleId, string permissionItemId)
        {
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseRoleEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, roleId));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId));
            return(permissionManager.Delete(parameters));
        }
Exemplo n.º 3
0
        public int Delete(string moduleId, string permissionItemId)
        {
            int returnValue = 0;
            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceCategory, BaseModuleEntity.TableName));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldResourceId, moduleId));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId));
            BasePermissionManager manager = new BasePermissionManager(this.DbHelper, this.UserInfo);

            returnValue = manager.Delete(parameters);
            return(returnValue);
        }
 /// <summary>
 /// 为了提高撤销的运行速度
 /// </summary>
 /// <param name="permissionManager">资源权限读写器</param>
 /// <param name="userId">用户主键</param>
 /// <param name="permissionItemId">权限主键</param>
 /// <returns>影响行数</returns>
 private int Revoke(BasePermissionManager permissionManager, string userId, string permissionItemId)
 {
     List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
     parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldResourceCategory, BaseUserEntity.TableName));
     parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldResourceId, userId));
     parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId));
     return permissionManager.Delete(parameters);
 }
 /// <summary>
 /// 撤销用户全部权限
 /// </summary>
 /// <param name="roleId">角色主键</param>
 /// <returns>影响行数</returns>
 public int RevokeAll(string userId)
 {
     BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
     List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
     parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldResourceCategory, BaseUserEntity.TableName));
     parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldResourceId, userId));
     return permissionManager.Delete(parameters);
 }
 public int Delete(string moduleId, string permissionItemId)
 {
     int returnValue = 0;
     List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
     parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldResourceCategory, BaseModuleEntity.TableName));
     parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldResourceId, moduleId));
     parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldPermissionItemId, permissionItemId));
     BasePermissionManager manager = new BasePermissionManager(this.DbHelper, this.UserInfo);
     returnValue=manager.Delete(parameters);
     return returnValue;
 }
        /// <summary>
        /// 撤消资源的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="resourceCategory">资源分类</param>
        /// <param name="resourceId">资源主键</param>
        /// <param name="revokePermissionItemIds">权限主键</param>
        /// <returns>影响的行数</returns>
        public int RevokeResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] revokePermissionItemIds)
        {
            // 写入调试信息
            #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);
                    // BaseRoleScopeManager manager = new BaseRoleScopeManager(dbHelper, userInfo);
                    // 小心异常,检查一下参数的有效性
                    if (revokePermissionItemIds != null)
                    {
                        BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo);
                        for (int i = 0; i < revokePermissionItemIds.Length; i++)
                        {
                            List<KeyValuePair<string, object>> parameters = new List<KeyValuePair<string, object>>();
                            parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldResourceCategory, resourceCategory));
                            parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldResourceId, resourceId));
                            parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldPermissionItemId, revokePermissionItemIds[i]));
                            // returnValue += permissionManager.SetDeleted(parameters);
                            returnValue += permissionManager.Delete(parameters);
                        }
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_RevokeResourcePermission, 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;
        }