/// <summary>
        /// 获取api资源
        /// </summary>
        /// <returns></returns>
        public async Task <PaginationResult <ApiScopeDto> > GetApiScopesAsync(int?skip, int?take, string search)
        {
            var query = ApiScopes;

            if (!string.IsNullOrEmpty(search))
            {
                search = search.Trim();
                query  = query.Where(e => e.Name.Contains(search) || e.DisplayName.Contains(search) || e.Description.Contains(search));
            }

            int total = await query.CountAsync().ConfigureAwait(false);

            skip ??= 0;
            take ??= 10;

            List <ApiScope> resources = await query.Skip(skip.Value).Take(take.Value).ToListAsync().ConfigureAwait(false);

            var dtos = resources.Select(e => ApiScopeDto.FromDbEntity(mapper, e));

            return(new PaginationResult <ApiScopeDto>
            {
                Succeeded = true,
                Total = total,
                Rows = dtos.ToList(),
                PageSize = take.Value
            });
        }
        public static ApiScopeDto FromDbEntity(IMapper mapper, ApiScope apiScopeEntity)
        {
            var         model       = apiScopeEntity.ToModel();
            ApiScopeDto apiScopeDto = mapper.Map <ApiScopeDto>(model);

            apiScopeDto.Id = apiScopeEntity.Id;
            return(apiScopeDto);
        }
        /// <summary>
        /// 通过id获取api作用域
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task <ApiScopeDto> GetApiScopeByIdAsync(int id)
        {
            var apiScope = await ApiScopes
                           .AsNoTracking()
                           .FirstOrDefaultAsync(e => e.Id == id).ConfigureAwait(false);

            if (apiScope == null)
            {
                return(null);
            }

            var dto = ApiScopeDto.FromDbEntity(mapper, apiScope);

            return(dto);
        }
        /// <summary>
        /// 创建或者更新api作用域
        /// </summary>
        /// <param name="dto"></param>
        /// <returns></returns>
        public async Task <Result> CreateOrUpdateApiScopeAsync(ApiScopeDto dto)
        {
            var entity = dto.ToDbEntity();

            if (entity.Id == 0)
            {
                //创建
                await configurationDbContext.ApiScopes.AddAsync(entity).ConfigureAwait(false);
            }
            else
            {
                var fromDbEntity = await ApiScopes.FirstOrDefaultAsync(e => e.Id == entity.Id).ConfigureAwait(false);

                if (fromDbEntity == null)
                {
                    return(FailedResult("不存在api作用域"));
                }

                fromDbEntity = mapper.Map(entity, fromDbEntity);
            }

            try
            {
                int rows = await configurationDbContext.SaveChangesAsync().ConfigureAwait(false);

                if (rows == 0)
                {
                    return(FailedResult("已执行,但未更新数据库"));
                }
                return(OkResult());
            }
            catch (DbUpdateException ex)
            {
                return(FailedResult(ex));
            }
        }