Example #1
0
        public async Task <IResultModel> UpdateSortList(SortUpdateModel <Guid> model)
        {
            if (model.Options == null || !model.Options.Any())
            {
                return(ResultModel.Failed("不包含数据"));
            }

            using (var uow = _dbContext.NewUnitOfWork())
            {
                foreach (var option in model.Options)
                {
                    var entity = await _menuRepository.GetAsync(option.Id, uow);

                    if (entity == null)
                    {
                        return(ResultModel.Failed());
                    }

                    entity.Sort = option.Sort;
                    if (!await _menuRepository.UpdateAsync(entity, uow))
                    {
                        return(ResultModel.Failed());
                    }
                }

                //清除账户菜单缓存
                await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_MENUS);

                uow.Commit();
            }

            return(ResultModel.Success());
        }
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            if (permissions == null || !permissions.Any())
            {
                return(ResultModel.Failed("未找到权限信息"));
            }

            using var uow = _dbContext.NewUnitOfWork();

            //先清除已有权限信息
            if (await _repository.ClearAsync(uow))
            {
                foreach (var permission in permissions)
                {
                    if (!await _repository.AddAsync(permission, uow))
                    {
                        uow.Rollback();
                        return(ResultModel.Failed("同步失败"));
                    }
                }

                uow.Commit();

                //删除所有账户的缓存信息
                await _cacheHandler.RemoveByPrefixAsync(CacheKeys.AccountPermissions);

                return(ResultModel.Success());
            }
            return(ResultModel.Failed("同步失败"));
        }
        public async Task <IResultModel> Clear(string prefix)
        {
            if (prefix.IsNull())
            {
                return(ResultModel.Failed());
            }

            await _cacheHandler.RemoveByPrefixAsync(prefix);

            return(ResultModel.Success());
        }
Example #4
0
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            if (!_options.RefreshModuleOrPermission)
            {
                return(ResultModel.Success());
            }

            if (permissions == null || !permissions.Any())
            {
                return(ResultModel.Failed("未找到权限信息"));
            }

            _logger.LogDebug("Sync Permission Info");

            using var uow = _dbContext.NewUnitOfWork();

            //先清除已有权限信息
            if (await _repository.ClearAsync(uow))
            {
                foreach (var permission in permissions)
                {
                    if (!await _repository.AddAsync(permission, uow))
                    {
                        uow.Rollback();
                        return(ResultModel.Failed("同步失败"));
                    }
                }

                uow.Commit();

                //删除所有账户的权限缓存
                await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_PERMISSIONS);

                return(ResultModel.Success());
            }

            return(ResultModel.Failed("同步失败"));
        }
Example #5
0
        public async Task <IResultModel> Sync(List <PermissionEntity> permissions)
        {
            using var uow = _dbContext.NewUnitOfWork();

            #region ==同步模块信息==

            var modules = _moduleCollection.Select(m => new ModuleEntity
            {
                Number  = m.Id,
                Name    = m.Name,
                Code    = m.Code,
                Icon    = m.Icon,
                Version = m.Version,
                Remarks = m.Description
            });

            _logger.LogDebug("Sync Module Info");

            foreach (var module in modules)
            {
                if (!await _repository.Exists(module, uow))
                {
                    if (!await _repository.AddAsync(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
                else
                {
                    if (!await _repository.UpdateByCode(module))
                    {
                        return(ResultModel.Failed());
                    }
                }
            }

            #endregion

            #region ==同步权限信息=

            if (permissions != null && permissions.Any())
            {
                _logger.LogDebug("Sync Permission Info");

                //先清除已有权限信息
                if (await _permissionRepository.ClearAsync(uow))
                {
                    foreach (var permission in permissions)
                    {
                        if (!await _permissionRepository.AddAsync(permission, uow))
                        {
                            return(ResultModel.Failed("同步失败"));
                        }
                    }

                    //删除所有账户的权限缓存
                    await _cacheHandler.RemoveByPrefixAsync(CacheKeys.ACCOUNT_PERMISSIONS);
                }
            }

            #endregion

            uow.Commit();

            return(ResultModel.Success());
        }