Пример #1
0
 public Builder()
 {
     _query = new PageQuery <TEntity>
     {
         Predicate = s => true
     };
 }
Пример #2
0
 public static IPaged <T> GetPagedBuiltByParameters(
     IQueryable <T> sourceQuery,
     IPageQuery pageQuery,
     string[] defaultSortKeys)
 {
     return(sourceQuery
            .ToPaged(pageQuery, defaultSortKeys.ToArray()));
 }
Пример #3
0
 public static async Task <IPaged <T> > GetPagedBuiltByParametersAsync(
     IQueryable <T> sourceQuery,
     Func <IQueryable <T>, CancellationToken, Task <List <T> > > toListAsync,
     IPageQuery pageQuery,
     string[] defaultSortKeys,
     CancellationToken ctok)
 {
     return(await sourceQuery.ToPagedAsync(toListAsync, pageQuery, defaultSortKeys.ToArray(), ctok));
 }
Пример #4
0
 public static IPaged <TResult> GetPagedBuiltByParameters <TResult>(
     IQueryable <T> sourceQuery,
     Expression <Func <T, TResult> > selector,
     IPageQuery pageQuery,
     string[] defaultSortKeys)
     where TResult : class
 {
     return(sourceQuery
            .ToPaged(selector, pageQuery, defaultSortKeys.ToArray()));
 }
Пример #5
0
        /// <summary>
        ///     Gets the paged list.
        /// </summary>
        /// <param name="query">查询</param>
        /// <returns>PagedList&lt;TaskQueue&gt;.</returns>
        /// <exception cref="ArgumentNullException">query</exception>
        public PagedList <TaskQueue> GetPagedList(IPageQuery <TaskQueue> query)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            return(null);
            // return Repository<ITaskQueueRepository>().GetPage(query);
        }
Пример #6
0
        public static Page <T> ToPage <T>(this IOrderedQueryable <T> list, IPageQuery query)
        {
            var count = list.Count();
            var items = list.Skip(query.Skip).Take(query.Take).ToList();

            return(new Page <T>()
            {
                Items = items,
                Count = count
            });
        }
Пример #7
0
        public async Task <IPageResult <TEntity> > PagingAsync(IPageQuery <TEntity> query, CancellationToken cancellationToken = default(CancellationToken))
        {
            var data = await Set.AsNoTracking()
                       .Where(query.Predicate)
                       .OrderBy($"{query.OrderBy} {(query.IsDesc ? "desc" : "asc")}")
                       .Skip(query.Skip)
                       .Take(query.Take)
                       .ToListAsync(cancellationToken);

            return(new PageResult <TEntity>
                   .Builder(data)
                   .CurrentPage(query.CurrentPage)
                   .PageSize(query.PageSize)
                   .TotalCount(await CountAsync(query.Predicate, cancellationToken))
                   .Build());
        }
Пример #8
0
        public IPageResult <TEntity> Paging(IPageQuery <TEntity> query)
        {
            var data = Set.AsNoTracking()
                       .Where(query.Predicate)
                       .OrderBy($"{query.OrderBy} {(query.IsDesc ? "desc" : "asc")}")
                       .Skip(query.Skip)
                       .Take(query.Take)
                       .ToList();

            return(new PageResult <TEntity>
                   .Builder(data)
                   .CurrentPage(query.CurrentPage)
                   .PageSize(query.PageSize)
                   .TotalCount(Count(query.Predicate))
                   .Build());
        }
Пример #9
0
        public PagedList <TEntity> GetPagedList(IPageQuery <TEntity> queryCriteria)
        {
            var query = UnitOfWork.Set <TEntity>();

            if (queryCriteria == null)
            {
                return(PagedList <TEntity> .Create(query.ToList(), query.Count(), query.Count(), 1));
            }

            var count       = queryCriteria.ExecuteCountQuery(query);
            var queryResult = queryCriteria.Execute(query);
            var resultList  = queryResult.ToList();

            resultList.ForEach(r => { r = JsonMapping.ConvertToExtension(r); });
            return(PagedList <TEntity> .Create(resultList, count, queryCriteria.PageSize, queryCriteria.PageIndex));
        }
Пример #10
0
        internal static IPaged <T> ToPaged <T>(
            this IQueryable <T> queryable,
            IPageQuery pageQuery,
            string[] defaultSortKeys)
            where T : class
        {
            var pagedIQueryable = queryable.GetPerPageIQueryable(pageQuery, defaultSortKeys, out var totalItemsCount);
            var items           = pagedIQueryable.ToList();
            var result          = new Paged <T>(
                items,
                pageQuery.PageIndex,
                pageQuery.PageSize,
                pageQuery.IndexFrom,
                totalItemsCount);

            return(result);
        }
Пример #11
0
        internal static IQueryable <T> GetPerPageIQueryable <T>(
            this IQueryable <T> queryable,
            IPageQuery pageQuery,
            string[] defaultSortKeys,
            out int totalItems)
            where T : class
        {
            if (pageQuery == null)
            {
                throw new ArgumentNullException(nameof(pageQuery));
            }
            if (!string.IsNullOrWhiteSpace(pageQuery.Keyword))
            {
                queryable = queryable.WhereByKeyword(
                    pageQuery.Keyword,
                    pageQuery.SearchFields.Pascalize());
            }
            totalItems = queryable.Count();
            var pageSize  = PageQuery.DefaultPageSize;
            var pageIndex = pageQuery.IndexFrom.Id;

            if (pageQuery.PageSize > 0)
            {
                pageSize = pageQuery.PageSize > PageQuery.MaxPageSize ? PageQuery.MaxPageSize : pageQuery.PageSize;
            }
            if (pageQuery.PageIndex > pageQuery.IndexFrom)
            {
                pageIndex = pageQuery.PageIndex;
            }
            if (pageQuery.Sorts != null && IsValidSorts <T>(pageQuery.Sorts))
            {
                queryable = queryable.ApplySorting(pageQuery.Sorts);
            }
            else
            {
                if (defaultSortKeys.Any())
                {
                    queryable = queryable.OrderBy(string.Join(",", defaultSortKeys));
                }
            }
            var result = queryable.Skip((pageIndex - pageQuery.IndexFrom.Id) * pageSize)
                         .Take(pageSize);

            return(result);
        }
Пример #12
0
        internal static IPaged <T> ToPaged <T>(
            this IQueryable <T> queryable,
            IPageQuery pageQuery,
            string[] defaultSortKeys)
            where T : class
        {
            var pagedIQueryable = queryable.GetPerPageIQueryable(pageQuery, defaultSortKeys, out var totalItemsCount);
            var items           = pagedIQueryable.ToList();

            return(new Paged <T>(
                       items,
                       ObjectDictionaryHelpers.GetPublicPropertyNames <T>(),
                       defaultSortKeys,
                       totalItemsCount,
                       pageQuery.PageIndex,
                       pageQuery.PageSize,
                       pageQuery.IndexFrom,
                       true));
        }
Пример #13
0
        internal static async Task <IPaged <T> > ToPagedAsync <T>(
            this IQueryable <T> queryable,
            IPageQuery pageQuery,
            string[] defaultSortKeys,
            CancellationToken ctok = default)
            where T : class
        {
            var pagedIQueryable = queryable.GetPerPageIQueryable(pageQuery, defaultSortKeys, out var totalItemsCount);
            var items           = await pagedIQueryable.ResolvedToListAsync(ctok);

            var result = new Paged <T>(
                items,
                pageQuery.PageIndex,
                pageQuery.PageSize,
                pageQuery.IndexFrom,
                totalItemsCount);

            return(result);
        }
Пример #14
0
        internal static async Task <IPaged <T> > ToPagedAsync <T>(
            this IQueryable <T> queryable,
            Func <IQueryable <T>, CancellationToken, Task <List <T> > > toListAsync,
            IPageQuery pageQuery,
            string[] defaultSortKeys,
            CancellationToken ctok = default)
            where T : class
        {
            var pagedIQueryable = queryable.GetPerPageIQueryable(pageQuery, defaultSortKeys, out var totalItemsCount);
            var items           = await toListAsync(pagedIQueryable, ctok);

            return(new Paged <T>(
                       items,
                       ObjectDictionaryHelpers.GetPublicPropertyNames <T>(),
                       defaultSortKeys,
                       totalItemsCount,
                       pageQuery.PageIndex,
                       pageQuery.PageSize,
                       pageQuery.IndexFrom,
                       true));
        }
        public static IQueryable <T> TakePageResult <T>(this IQueryable <T> query, IPageQuery pageData)
        {
            if (query == null)
            {
                throw new ArgumentNullException(nameof(query));
            }

            if (pageData == null)
            {
                throw new ArgumentNullException(nameof(pageData));
            }

            if (pageData.PageNr <= 0)
            {
                throw new ArgumentException(nameof(IPageQuery.PageNr) + " should be equal and greater than 1.");
            }

            if (pageData.PageSize <= 0)
            {
                throw new ArgumentException("Invalid page size.");
            }

            return(query.Skip((pageData.PageNr - 1) * pageData.PageSize).Take(pageData.PageSize));
        }
Пример #16
0
 public Task <PagedList <TEntity> > GetPagedListAsync(IPageQuery <TEntity> query)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Create new instance of <see cref="SelectAndPageQuery"/>
 /// </summary>
 /// <param name="selectQuery">Select query.</param>
 /// <param name="pageQuery">Page query.</param>
 public SelectAndPageQuery(ISelectQuery selectQuery, IPageQuery pageQuery)
     : base(new IQuery[] { selectQuery, pageQuery })
 {
 }
Пример #18
0
 public async Task <IPageResult <IdS4IdentityResource> > SearchAsync(IPageQuery <IdS4IdentityResource> query)
 {
     return(await _identityResourceRepository.PagingAsync(query));
 }
Пример #19
0
        public PagedList <TEntity> GetPagedList(IPageQuery <TEntity> queryCriteria)
        {
            var predicate = queryCriteria.BuildExpression();

            return(GetPagedList(predicate, queryCriteria.PageSize, queryCriteria.PageIndex));
        }
Пример #20
0
 public PageLink(IPageQuery pageQuery, string text)
 {
     PageQuery = pageQuery;
     Text      = text;
 }
Пример #21
0
 public static int Skip <T>(this IPageQuery <T> query) => (query.Page - 1) * query.PageSize;
Пример #22
0
 public static int Take <T>(this IPageQuery <T> query) => query.PageSize;
 /// <summary>
 /// Create new instance of <see cref="FilterAndPageQuery"/>
 /// </summary>
 /// <param name="filterQuery">Filter query.</param>
 /// <param name="pageQuery">Page query.</param>
 public FilterAndPageQuery(IFilterQuery filterQuery, IPageQuery pageQuery)
     : base(new IQuery[] { filterQuery, pageQuery })
 {
 }
Пример #24
0
 public async Task <IPageResult <Log> > PagingAsync(IPageQuery <Log> query)
 {
     return(await _logRepository.PagingAsync(query));
 }
Пример #25
0
 public PagedList <TEntity> GetPagedList(IPageQuery <TEntity> query)
 {
     return(Store.GetPagedList(query));
 }