/// <summary>
        /// 保存授权资源
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public Task <bool> SaveSysApiResource(SysApiResourceInput model)
        {
            var isRepeat = _sysApiResourceRepository.GetAllList(w => w.ResourceName == model.ResourceName && w.Id != model.Id).Any();

            if (isRepeat)
            {
                throw new UserFriendlyException("授权资源重复", "您设置的授权资源" + model.ResourceName + "重复!");
            }
            if (model.Id == null)
            {
                SysApiResource modelInput = ObjectMapper.Map <SysApiResource>(model);
                _sysApiResourceRepository.InsertAndGetIdAsync(modelInput);
            }
            else
            {
                SysApiResource data = _sysApiResourceRepository.Get(model.Id.Value);
                SysApiResource m    = ObjectMapper.Map(model, data);
                _sysApiResourceRepository.UpdateAsync(m);
            }
            //移除缓存
            _sysIdentityServerCacheAppService.RemoveResourcesCache();
            _sysIdentityServerCacheAppService.RemoveClientAndAccountCache();
            _sysIdentityServerCacheAppService.RemoveClientCache();
            return(Task.FromResult(true));
        }
Example #2
0
        /// <summary>
        /// 获取客户与资源
        /// </summary>
        /// <returns></returns>
        private List <ApiResource> GetAllResources()
        {
            //获取客户与资源关系
            var apiResourceList = _sysApiResourceRepository.GetAllList(w => w.IsActive);
            //
            List <ApiResource> resourceList = new List <ApiResource>();

            //
            if (apiResourceList == null && !apiResourceList.Any())
            {
                return(resourceList);
            }
            //
            foreach (var resource in apiResourceList)
            {
                resourceList.Add(new ApiResource(resource.ResourceName, resource.ResourceDisplayName));
            }
            return(resourceList);
        }