コード例 #1
0
ファイル: AdController.cs プロジェクト: Gietson/FlatScraper
        public async Task <IActionResult> Get(FilterQuery filter)
        {
            try
            {
                string pageString          = HttpContext.Request.Headers["X-Pagination-Page"];
                string resultPerPageString = HttpContext.Request.Headers["X-Pagination-ResultPerPage"];

                Int32.TryParse(pageString, out int page);
                Int32.TryParse(resultPerPageString, out int resultsPerPage);
                PagedQueryBase query = new PagedQueryBase()
                {
                    Page           = page,
                    ResultsPerPage = resultsPerPage,
                    Filter         = filter
                };

                var ads = await _adService.BrowseAsync(query);

                return(Json(ads));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
コード例 #2
0
 public UserSpecification(PagedQueryBase pageQuery, string email, string name)
     : base(user =>
            (string.IsNullOrEmpty(email) || user.Email.Contains(email)) ||
            (string.IsNullOrEmpty(name) || user.FullName.Contains(name)))
 {
     AddInclude(u => u.Roles);
     AddInclude("Roles.Role");
     ApplyPaging(pageQuery.Skip, pageQuery.PageSize);
 }
コード例 #3
0
        public static PagedResult <T> Paginate <T>(this IQueryable <T> collection, PagedQueryBase query)
        {
            if (!collection.Any())
            {
                return(PagedResult <T> .Empty);
            }
            var totalResults = collection.Count();
            var totalPages   = (int)Math.Ceiling((decimal)totalResults / query.Results);
            var data         = collection.Skip((query.Page - 1) * query.Results).Take(query.Results);

            return(PagedResult <T> .Create(data, query.Page, query.Results, totalPages, totalResults));
        }
コード例 #4
0
 public static PagedResult <T> Paginate <T>(this IEnumerable <T> collection, PagedQueryBase query)
 => collection.Paginate(query.Page, query.Results);
コード例 #5
0
 public static IFindFluent <T, T> Limit <T>(this IFindFluent <T, T> findFluent, PagedQueryBase query)
 {
     return(findFluent.Limit(query.Page, query.Results));
 }
コード例 #6
0
 public static async Task <PagedResult <T> > PaginateAsync <T>(this IFindFluent <T, T> findFluent,
                                                               PagedQueryBase query)
 {
     return(await findFluent.PaginateAsync(query.Page, query.Results));
 }
コード例 #7
0
 public static Task <PagedResult <T> > PaginateAsync <T>(this IMongoQueryable <T> values, PagedQueryBase query)
 => values.PaginateAsync(query.Page, query.Results);
コード例 #8
0
 public static IQueryable <T> Limit <T>(this IQueryable <T> queryable, PagedQueryBase query)
 => queryable.Limit(query.Page, query.Results);
コード例 #9
0
ファイル: Pagination.cs プロジェクト: alpergunay/Ax3.IMS
 public static async Task <PagedResult <T> > PaginateAsync <T>(this IMongoQueryable <T> collection, PagedQueryBase query)
 => await collection.PaginateAsync(query.Page, query.Results);
コード例 #10
0
 /* sdfs
  *  IQueryable<T> normally represents an operation that will be performed later (e.g. with LINQ to SQL).
  * A separate interface is needed because the next operation might be another sort, which needs to be treated differently to the IOrderedQueryable<T>
  */
 public static async Task <PagedResult <T> > PaginateAsync <T>(this IQueryable <T> collection, PagedQueryBase query)
 {
     return(await collection.PaginateAsync(query.Page, query.Results));
 }
コード例 #11
0
 public static IQueryable <T> Limit <T>(this IQueryable <T> collection, PagedQueryBase query)
 => collection.Limit(query.Page, query.PageSize);
コード例 #12
0
 public static IQueryable <T> Limit <T>(this IQueryable <T> collection, PagedQueryBase query) where T : BaseEntity
 => collection.Limit(query.Page, query.Results);
コード例 #13
0
 public static async Task <PagedResult <T> > PaginateAsync <T>(this IQueryable <T> collection, PagedQueryBase query) where T : BaseEntity
 => await collection.PaginateAsync(query.Page, query.Results);
コード例 #14
0
ファイル: AdService.cs プロジェクト: Gietson/FlatScraper
        public async Task <PagedResult <AdDto> > BrowseAsync(PagedQueryBase query)
        {
            var ad = await _adRepository.BrowseAsync(query);

            return(_mapper.Map <PagedResult <AdDto> >(ad));
        }
コード例 #15
0
 public static PagedResult <T> Paginate <T>(this T[] values, PagedQueryBase query)
 => Paginate(values, query.Page, query.Results);
コード例 #16
0
ファイル: FilterAd.cs プロジェクト: Gietson/FlatScraper
 public static IMongoQueryable <Ad> FilterAds(this IMongoQueryable <Ad> collection,
                                              PagedQueryBase query)
 => collection.FilterAds(query.Filter);
コード例 #17
0
        public async Task <PagedResult <T> > GetAllPagedAsync(ISpecification <T> specification, PagedQueryBase query)
        {
            var totalResults = await _unitOfWork.Context.Set <T>().CountAsync();

            var totalPages = (int)Math.Ceiling((decimal)totalResults / query.PageSize);
            var data       = ApplySpecification(specification).ToList();;

            return(PagedResult <T> .Create(data, query.Page, query.PageSize, totalPages, totalResults));
        }
コード例 #18
0
ファイル: AdRepository.cs プロジェクト: Gietson/FlatScraper
 public async Task <PagedResult <Ad> > BrowseAsync(PagedQueryBase query)
 => await Ad.AsQueryable()
 .FilterAds(query)
 .OrderByDescending(x => x.AdDetails.CreateAt)
 .PaginateAsync(query);
コード例 #19
0
 public static IQueryable <T> Limit <T>(this IQueryable <T> collection, PagedQueryBase query)
 {
     return(collection.Limit(query.Page, query.Results));
 }
コード例 #20
0
        ///// <summary>
        ///// Asynchronously does any sort and gets one page of results with model type.
        ///// </summary>
        ///// <typeparam name="TEntity">Type of source</typeparam>
        ///// <typeparam name="TDto">Type of destination target results</typeparam>
        ///// <param name="source">Data source</param>
        ///// <param name="query">Paged query</param>
        ///// <param name="mapper">AutoMapper instance</param>
        ///// <returns></returns>
        //public static async Task<PagedResult<TDto>> GetPagedAsync<TEntity, TDto>(this IQueryable<TEntity> source,
        //                                    PagedQueryBase query,
        //                                    IMapper mapper) where TDto : class
        //{

        //    if (!string.IsNullOrEmpty(query.SortOn) && !string.IsNullOrEmpty(query.SortDirection))
        //    {
        //        source = query.SortDirection.ToUpper() == "ASC" ? source.OrderBy(query.SortOn) : source.OrderByDescending(query.SortOn);
        //    }

        //    return new PagedResult<TDto>
        //    {
        //        CurrentPage = query.CurrentPage,
        //        PageSize = query.PageSize,
        //        RowCount = await source.CountAsync(),
        //        Results = await source.Skip(query.SkipCount()).Take(query.PageSize).ProjectTo<TDto>(mapper.ConfigurationProvider).ToListAsync()
        //    };
        //}

        /// <summary>
        /// Asynchronously does any sort and gets one page of results with model type.
        /// </summary>
        /// <typeparam name="TResponse">Type of response</typeparam>
        /// <typeparam name="TEntity">Type of source</typeparam>
        /// <typeparam name="TDto">Type of destination target results</typeparam>
        /// <param name="source">Data source</param>
        /// <param name="query">Paged query</param>
        /// <param name="mapper">AutoMapper instance</param>
        /// <param name="customSortBy"></param>
        /// <param name="thenSortBy"></param>
        /// <returns></returns>
        public static async Task <TResponse> GetPagedAsync <TResponse, TEntity, TDto>(this IQueryable <TEntity> source,
                                                                                      PagedQueryBase query, IMapper mapper, Expression <Func <TEntity, object> > customSortBy = null,
                                                                                      Expression <Func <TEntity, object> > thenSortBy = null)
            where TDto : class where TResponse : PagedResult <TDto>, new()
        {
            if (!string.IsNullOrEmpty(query.SortDirection))
            {
                if (customSortBy != null)
                {
                    if (query.SortDirection.ToUpper() == "ASC")
                    {
                        source = thenSortBy != null
                            ? source.OrderBy(customSortBy).ThenBy(thenSortBy)
                            : source.OrderBy(customSortBy);
                    }
                    else
                    {
                        source = thenSortBy != null
                            ? source.OrderByDescending(customSortBy).ThenByDescending(thenSortBy)
                            : source.OrderByDescending(customSortBy);
                    }
                }
                else if (!string.IsNullOrEmpty(query.SortOn))
                {
                    source = query.SortDirection.ToUpper() == "ASC"
                        ? source.OrderBy(query.SortOn)
                        : source.OrderByDescending(query.SortOn);
                }
            }

            return(new TResponse
            {
                CurrentPage = query.CurrentPage,
                PageSize = query.PageSize,
                RowCount = await source.CountAsync(),
                Results = await source.Skip(query.SkipCount()).Take(query.PageSize).ProjectTo <TDto>(mapper.ConfigurationProvider).ToListAsync()
            });
        }
コード例 #21
0
ファイル: Pagination.cs プロジェクト: alpergunay/Ax3.IMS
 public static IMongoQueryable <T> Limit <T>(this IMongoQueryable <T> collection, PagedQueryBase query)
 => collection.Limit(query.Page, query.Results);
コード例 #22
0
 public static async Task <PagedResult <T> > PaginateAsync <T>(this IQueryable <T> queryable, PagedQueryBase query)
 => await queryable.PaginateAsync(query.Page, query.Results);