/// <summary>
        /// 授予角色的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleId">角色主键</param>
        /// <param name="grantPermissionId">授予权限数组</param>
        /// <returns>数据主键</returns>
        public string GrantRolePermissionById(BaseUserInfo userInfo, string roleId, string grantPermissionId)
        {
            string result = string.Empty;

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

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

            return(result);
        }
Exemple #2
0
        /// <summary>
        /// 给角色权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleName">角色名</param>
        /// <param name="permissionCode">权限编号</param>
        /// <returns>主键</returns>
        public string GrantRolePermission(BaseUserInfo userInfo, string roleName, string permissionCode)
        {
            string result = string.Empty;

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

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

            return(result);
        }
        /// <summary>
        /// 授予角色的权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleIds">角色主键数组</param>
        /// <param name="grantPermissionIds">授予权限数组</param>
        /// <returns>影响的行数</returns>
        public int GrantRolePermissions(BaseUserInfo userInfo, string[] roleIds, string[] grantPermissionIds)
        {
            int result = 0;

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

            ServiceUtil.ProcessUserCenterWriteDb(userInfo, parameter, (dbHelper) =>
            {
                string tableName = userInfo.SystemCode + "Permission";
                var manager      = new BaseRolePermissionManager(dbHelper, userInfo, tableName);
                // 小心异常,检查一下参数的有效性
                if (roleIds != null && grantPermissionIds != null)
                {
                    result += manager.Grant(userInfo.SystemCode, roleIds, grantPermissionIds);
                }
            });

            return(result);
        }
Exemple #4
0
        /// <summary>
        /// 给角色权限
        /// </summary>
        /// <param name="userInfo">用户</param>
        /// <param name="roleName">角色名</param>
        /// <param name="permissionItemCode">权限编号</param>
        /// <returns>主键</returns>
        public string GrantRolePermission(BaseUserInfo userInfo, string roleName, string permissionItemCode)
        {
            // 加强安全验证防止未授权匿名调用
            #if (!DEBUG)
            LogOnService.UserIsLogOn(userInfo);
            #endif

            string returnValue = string.Empty;
            using (IDbHelper dbHelper = DbHelperFactory.GetHelper(BaseSystemInfo.UserCenterDbType))
            {
                try
                {
                    dbHelper.Open(UserCenterDbConnection);
                    BaseRoleManager           roleManager           = new BaseRoleManager(dbHelper, userInfo);
                    string                    roleId                = roleManager.GetId(new KeyValuePair <string, object>(BaseRoleEntity.FieldRealName, roleName));
                    BasePermissionItemManager permissionItemManager = new BasePermissionItemManager(dbHelper, userInfo);
                    string                    permissionItemId      = permissionItemManager.GetId(new KeyValuePair <string, object>(BasePermissionItemEntity.FieldCode, permissionItemCode));
                    if (!String.IsNullOrEmpty(roleId) && !String.IsNullOrEmpty(permissionItemId))
                    {
                        BaseRolePermissionManager rolePermissionManager = new BaseRolePermissionManager(dbHelper, userInfo);
                        returnValue = rolePermissionManager.Grant(roleId, permissionItemId);
                    }
                }
                catch (Exception ex)
                {
                    BaseExceptionManager.LogException(dbHelper, userInfo, ex);
                    throw ex;
                }
                finally
                {
                    dbHelper.Close();
                }
            }

            return(returnValue);
        }