public int Add(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));
            parameters.Add(new KeyValuePair<string, object>(BasePermissionEntity.FieldDeletionStateCode, 0));

            // 检查记录是否重复
            if (!this.Exists(parameters))
            {
                BasePermissionEntity permissionEntity = new BasePermissionEntity();
                permissionEntity.ResourceId = moduleId;
                permissionEntity.ResourceCategory = BaseModuleEntity.TableName;
                permissionEntity.Enabled = 1;
                permissionEntity.DeletionStateCode = 0;
                permissionEntity.PermissionId = int.Parse(permissionItemId);
                BasePermissionManager permissionManager = new BasePermissionManager(this.DbHelper, this.UserInfo, this.CurrentTableName);
                permissionManager.AddEntity(permissionEntity);
                returnValue++;
            }
            return returnValue;
        }
Пример #2
0
        public int Add(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));
            parameters.Add(new KeyValuePair <string, object>(BasePermissionEntity.FieldDeletionStateCode, 0));

            // 检查记录是否重复
            if (!this.Exists(parameters))
            {
                BasePermissionEntity permissionEntity = new BasePermissionEntity();
                permissionEntity.ResourceId        = moduleId;
                permissionEntity.ResourceCategory  = BaseModuleEntity.TableName;
                permissionEntity.Enabled           = 1;
                permissionEntity.DeletionStateCode = 0;
                permissionEntity.PermissionId      = int.Parse(permissionItemId);
                BasePermissionManager permissionManager = new BasePermissionManager(this.DbHelper, this.UserInfo, this.CurrentTableName);
                permissionManager.AddEntity(permissionEntity);
                returnValue++;
            }
            return(returnValue);
        }
        //
        //  撤销权限的实现部分
        //

        #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));
        }
        /// <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));
        }
        public int Revoke(string[] roleIds, string permissionItemId)
        {
            int returnValue = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < roleIds.Length; i++)
            {
                returnValue += this.Revoke(permissionManager, roleIds[i], permissionItemId);
            }
            return(returnValue);
        }
        //
        // 授予权限的实现部分
        //

        #region private string Grant(BasePermissionManager permissionManager, string id, string userId, string permissionItemId) 为了提高授权的运行速度
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="Id">主键</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>主键</returns>
        private string Grant(BasePermissionManager permissionManager, string id, string userId, string permissionItemId)
        {
            string returnValue = string.Empty;
            BasePermissionEntity resourcePermissionEntity = new BasePermissionEntity();

            resourcePermissionEntity.ResourceCategory = BaseUserEntity.TableName;
            resourcePermissionEntity.ResourceId       = userId;
            resourcePermissionEntity.PermissionId     = int.Parse(permissionItemId);
            resourcePermissionEntity.Enabled          = 1;
            return(permissionManager.Add(resourcePermissionEntity));
        }
        //
        // 授予权限的实现部分
        //

        #region private string Grant(BasePermissionManager permissionManager, string id, string roleId, string permissionItemId) 为了提高授权的运行速度
        /// <summary>
        /// 为了提高授权的运行速度
        /// </summary>
        /// <param name="permissionManager">资源权限读写器</param>
        /// <param name="Id">主键</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>主键</returns>
        private string Grant(BasePermissionManager permissionManager, string roleId, string permissionItemId)
        {
            string returnValue = string.Empty;
            BasePermissionEntity resourcePermission = new BasePermissionEntity();

            resourcePermission.ResourceCategory = BaseRoleEntity.TableName;
            resourcePermission.ResourceId       = roleId;
            resourcePermission.PermissionId     = int.Parse(permissionItemId);
            // 防止不允许为NULL的错误发生
            resourcePermission.Enabled = 1;
            return(permissionManager.Add(resourcePermission));
        }
        public int Grant(string roleId, string[] permissionItemIds)
        {
            int returnValue = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < permissionItemIds.Length; i++)
            {
                this.Grant(permissionManager, roleId, permissionItemIds[i]);
                returnValue++;
            }
            return(returnValue);
        }
Пример #9
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);
        }
        public int Revoke(string[] userIds, string[] permissionItemIds)
        {
            int returnValue = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < userIds.Length; i++)
            {
                for (int j = 0; j < permissionItemIds.Length; j++)
                {
                    returnValue += this.Revoke(permissionManager, userIds[i], permissionItemIds[j]);
                }
            }
            return(returnValue);
        }
Пример #11
0
        public int Grant(string[] organizeIds, string[] permissionItemIds)
        {
            int returnValue = 0;
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < organizeIds.Length; i++)
            {
                for (int j = 0; j < permissionItemIds.Length; j++)
                {
                    this.Grant(permissionManager, organizeIds[i], permissionItemIds[j]);
                    returnValue++;
                }
            }
            return(returnValue);
        }
        public int Grant(string[] userIds, string permissionItemId)
        {
            int returnValue = 0;
            BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper);

            string[] sequenceIds = sequenceManager.GetBatchSequence(BasePermissionEntity.TableName, userIds.Length);
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            for (int i = 0; i < userIds.Length; i++)
            {
                this.Grant(permissionManager, sequenceIds[i], userIds[i], permissionItemId);
                returnValue++;
            }
            return(returnValue);
        }
 /// <summary>
 /// 撤销员工权限
 /// </summary>
 /// <param name="userId">用户主键</param>
 /// <param name="permissionItemId">权限主键</param>
 /// <returns>影响行数</returns>
 public int Revoke(string userId, string permissionItemId)
 {
     BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
     return this.Revoke(permissionManager, userId, permissionItemId);
 }
 /// <summary>
 /// 用户授予权限
 /// </summary>
 /// <param name="userId">用户主键</param>
 /// <param name="permissionItemId">权限主键</param>
 public string Grant(string userId, string permissionItemId)
 {
     BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
     return this.Grant(permissionManager, string.Empty, userId, permissionItemId);
 }
 public int Grant(string[] userIds, string[] permissionItemIds)
 {
     int returnValue = 0;
     BaseSequenceManager sequenceManager = new BaseSequenceManager(DbHelper);
     string[] sequenceIds = sequenceManager.GetBatchSequence(BasePermissionEntity.TableName, userIds.Length * permissionItemIds.Length);
     BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
     for (int i = 0; i < userIds.Length; i++)
     {
         for (int j = 0; j < permissionItemIds.Length; j++)
         {
             this.Grant(permissionManager, sequenceIds[i * permissionItemIds.Length + j], userIds[i], permissionItemIds[j]);
             returnValue++;
         }
     }
     return returnValue;
 }
 public int Revoke(string[] roleIds, string permissionItemId)
 {
     int returnValue = 0;
     BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
     for (int i = 0; i < roleIds.Length; i++)
     {
         returnValue += this.Revoke(permissionManager, roleIds[i], permissionItemId);
     }
     return returnValue;
 }
 public int Grant(string[] roleIds, string[] permissionItemIds)
 {
     int returnValue = 0;
     BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
     for (int i = 0; i < roleIds.Length; i++)
     {
         for (int j = 0; j < permissionItemIds.Length; j++)
         {
             this.Grant(permissionManager, roleIds[i], permissionItemIds[j]);
             returnValue++;
         }
     }
     return returnValue;
 }
 /// <summary>
 /// 为了提高授权的运行速度
 /// </summary>
 /// <param name="permissionManager">资源权限读写器</param>
 /// <param name="Id">主键</param>
 /// <param name="roleId">角色主键</param>
 /// <param name="permissionItemId">权限主键</param>
 /// <returns>主键</returns>
 private string Grant(BasePermissionManager permissionManager, string roleId, string permissionItemId)
 {
     string returnValue = string.Empty;
     BasePermissionEntity resourcePermission = new BasePermissionEntity();
     resourcePermission.ResourceCategory = BaseRoleEntity.TableName;
     resourcePermission.ResourceId = roleId;
     resourcePermission.PermissionId = int.Parse(permissionItemId);
     // 防止不允许为NULL的错误发生
     resourcePermission.Enabled = 1;
     return permissionManager.Add(resourcePermission);
 }
        /// <summary>
        /// 撤销角色权限
        /// </summary>
        /// <param name="roleId">角色主键</param>
        /// <param name="permissionItemId">权限主键</param>
        /// <returns>影响行数</returns>
        public int Revoke(string roleId, string permissionItemId)
        {
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            return(this.Revoke(permissionManager, roleId, permissionItemId));
        }
Пример #20
0
        /// <summary>
        /// 某个用户是否有相应的操作权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionItemCode">权限编号</param>
        /// <param name="permissionItemName">权限名称</param>
        /// <returns>是否有权限</returns>
        public bool IsAuthorizedByUser(BaseUserInfo userInfo, string userId, string permissionItemCode, string permissionItemName = null)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            bool returnValue = false;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    if (string.IsNullOrEmpty(userId))
                    {
                        userId = userInfo.Id;
                    }
                    #if (!DEBUG)
                        // 是超级管理员,就不用继续判断权限了
                        BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                        returnValue = userManager.IsAdministrator(userId);
                        if (returnValue)
                        {
                            return returnValue;
                        }
                    #endif

                    BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo);
                    returnValue = permissionManager.CheckPermissionByUser(userId, permissionItemCode, permissionItemName);
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_IsAuthorizedByUser, 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;
        }
Пример #21
0
        /// <summary>
        /// 获得某个用户的所有权限列表
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="userId">用户主键</param>
        /// <returns>数据表</returns>
        public DataTable GetPermissionDTByUser(BaseUserInfo userInfo, string userId)
        {
            // 写入调试信息
            #if (DEBUG)
                int milliStart = BaseBusinessLogic.StartDebug(userInfo, MethodBase.GetCurrentMethod());
            #endif

            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
                LogOnService.UserIsLogOn(userInfo);
            #endif

            DataTable dataTable = new DataTable(BasePermissionItemEntity.TableName);
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    string tableName = BasePermissionItemEntity.TableName;
                    if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                    {
                        tableName = BaseSystemInfo.SystemCode + "PermissionItem";
                    }
                    // 是否超级管理员
                    BaseUserManager userManager = new BaseUserManager(dbHelper, userInfo);
                    BasePermissionItemManager permissionItemManager = new BasePermissionItemManager(dbHelper, userInfo, tableName);
                    if (userManager.IsAdministrator(userId))
                    {
                        dataTable = permissionItemManager.GetDataTable();
                    }
                    else
                    {
                        tableName = BasePermissionEntity.TableName;
                        if (!string.IsNullOrEmpty(BaseSystemInfo.SystemCode))
                        {
                            tableName = BaseSystemInfo.SystemCode + "Permission";
                        }
                        BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo, tableName);
                        string[] ids = permissionManager.GetPermissionIdsByUser(userId);
                        // 若是以前赋予的权限,后来有些权限设置为无效了,那就不应该再获取哪些无效的权限才对。
                        // bug修正:没有赋值DataTable,导致返回值空
                        dataTable = permissionItemManager.GetDataTable(
                            new KeyValuePair<string, object>(BasePermissionItemEntity.FieldId, ids)
                            , new KeyValuePair<string, object>(BasePermissionItemEntity.FieldEnabled, 1)
                            , new KeyValuePair<string, object>(BasePermissionItemEntity.FieldDeletionStateCode, 0));
                    }
                    dataTable.TableName = tableName;
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_GetPermissionDTByUser, MethodBase.GetCurrentMethod());
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            // 写入调试信息
            #if (DEBUG)
                BaseBusinessLogic.EndDebug(MethodBase.GetCurrentMethod(), milliStart);
            #endif

            return dataTable;
        }
        /// <summary>
        /// 授予资源的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="resourceCategory">资源分类</param>
        /// <param name="resourceId">资源主键</param>
        /// <param name="grantPermissionItemIds">权限主键</param>
        /// <returns>影响的行数</returns>
        public int GrantResourcePermission(BaseUserInfo userInfo, string resourceCategory, string resourceId, string[] grantPermissionItemIds)
        {
            // 写入调试信息
            #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 roleScopeManager = new BaseRoleScopeManager(dbHelper, userInfo);
                    // 小心异常,检查一下参数的有效性
                    if (grantPermissionItemIds != null)
                    {
                        BasePermissionManager permissionManager = new BasePermissionManager(dbHelper, userInfo);
                        for (int i = 0; i < grantPermissionItemIds.Length; i++)
                        {
                            BasePermissionEntity resourcePermissionEntity = new BasePermissionEntity();
                            resourcePermissionEntity.ResourceCategory = resourceCategory;
                            resourcePermissionEntity.ResourceId = resourceId;
                            resourcePermissionEntity.PermissionId = int.Parse(grantPermissionItemIds[i]);
                            resourcePermissionEntity.Enabled = 1;
                            resourcePermissionEntity.DeletionStateCode = 0;
                            permissionManager.Add(resourcePermissionEntity);
                            returnValue++;
                        }
                    }
                    BaseLogManager.Instance.Add(dbHelper, userInfo, this.serviceName, AppMessage.PermissionService_GrantResourcePermission, 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>
        /// 撤消资源的权限
        /// </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;
        }
 /// <summary>
 /// 为了提高授权的运行速度
 /// </summary>
 /// <param name="permissionManager">资源权限读写器</param>
 /// <param name="Id">主键</param>
 /// <param name="userId">用户主键</param>
 /// <param name="permissionItemId">权限主键</param>
 /// <returns>主键</returns>
 private string Grant(BasePermissionManager permissionManager, string id, string userId, string permissionItemId)
 {
     string returnValue = string.Empty;
     BasePermissionEntity resourcePermissionEntity = new BasePermissionEntity();
     resourcePermissionEntity.ResourceCategory = BaseUserEntity.TableName;
     resourcePermissionEntity.ResourceId = userId;
     resourcePermissionEntity.PermissionId = int.Parse(permissionItemId);
     resourcePermissionEntity.Enabled = 1;
     return permissionManager.Add(resourcePermissionEntity);
 }
 public int Revoke(string[] userIds, string[] permissionItemIds)
 {
     int returnValue = 0;
     BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
     for (int i = 0; i < userIds.Length; i++)
     {
         for (int j = 0; j < permissionItemIds.Length; j++)
         {
             returnValue += this.Revoke(permissionManager, userIds[i], permissionItemIds[j]);
         }
     }
     return returnValue;
 }
        /// <summary>
        /// 用户授予权限
        /// </summary>
        /// <param name="userId">用户主键</param>
        /// <param name="permissionItemId">权限主键</param>
        public string Grant(string userId, string permissionItemId)
        {
            BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);

            return(this.Grant(permissionManager, string.Empty, userId, permissionItemId));
        }
 /// <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="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);
 }
 public int Grant(string[] organizeIds, string permissionItemId)
 {
     int returnValue = 0;
     BasePermissionManager permissionManager = new BasePermissionManager(DbHelper, UserInfo, this.CurrentTableName);
     for (int i = 0; i < organizeIds.Length; i++)
     {
         this.Grant(permissionManager, organizeIds[i], permissionItemId);
         returnValue++;
     }
     return returnValue;
 }