public async Task SeedAsync()
        {
            List <PermissionDefinition> linCmsAttributes = ReflexHelper.GeAssemblyLinCmsAttributes();

            List <LinPermission> insertPermissions = new List <LinPermission>();
            List <LinPermission> allPermissions    = await _permissionRepository.Select.ToListAsync();

            linCmsAttributes.ForEach(r =>
            {
                bool exist = allPermissions.Any(u => u.Module == r.Module && u.Name == r.Permission);
                if (!exist)
                {
                    insertPermissions.Add(new LinPermission(r.Permission, r.Module));
                }
            });
            await _permissionRepository.InsertAsync(insertPermissions);
        }
Example #2
0
        public Task SeedAsync()
        {
            List <PermissionDefinition> linCmsAttributes = ReflexHelper.GeAssemblyLinCmsAttributes();

            linCmsAttributes.ForEach(async r =>
            {
                bool exist = await _permissionRepository.Select
                             .Where(u => u.Module == r.Module && u.Name == r.Permission)
                             .AnyAsync();

                if (!exist)
                {
                    await _permissionRepository.InsertAsync(new LinPermission(r.Permission, r.Module));
                }
            });
            _permissionRepository.UnitOfWork.Commit();

            return(Task.CompletedTask);
        }
        /// <summary>
        /// 权限标签上的Permission改变时,删除数据库中存在的无效权限,并生成新的权限。
        /// </summary>
        /// <returns></returns>
        public async Task SeedAsync()
        {
            List <PermissionDefinition> linCmsAttributes = ReflexHelper.GeAssemblyLinCmsAttributes();

            List <LinPermission> insertPermissions = new List <LinPermission>();
            List <LinPermission> allPermissions    = await _permissionRepository.Select.ToListAsync();

            Expression <Func <LinGroupPermission, bool> > expression           = u => false;
            Expression <Func <LinPermission, bool> >      permissionExpression = u => false;

            allPermissions.ForEach(permissioin =>
            {
                if (!linCmsAttributes.Any(r => r.Permission == permissioin.Name))
                {
                    expression           = expression.Or(r => r.PermissionId == permissioin.Id);
                    permissionExpression = permissionExpression.Or(r => r.Id == permissioin.Id);
                }
            });

            int effectRows = await _permissionRepository.DeleteAsync(permissionExpression);

            effectRows += await _groupPermissionRepository.DeleteAsync(expression);

            _logger.LogInformation($"删除了{effectRows}条数据");

            linCmsAttributes.ForEach(r =>
            {
                bool exist = allPermissions.Any(u => u.Module == r.Module && u.Name == r.Permission);
                if (!exist)
                {
                    insertPermissions.Add(new LinPermission(r.Permission, r.Module));
                }
            });
            await _permissionRepository.InsertAsync(insertPermissions);

            _logger.LogInformation($"新增了{insertPermissions.Count}条数据");
        }