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)); } }
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); }
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)); }
public static PagedResult <T> Paginate <T>(this IEnumerable <T> collection, PagedQueryBase query) => collection.Paginate(query.Page, query.Results);
public static IFindFluent <T, T> Limit <T>(this IFindFluent <T, T> findFluent, PagedQueryBase query) { return(findFluent.Limit(query.Page, query.Results)); }
public static async Task <PagedResult <T> > PaginateAsync <T>(this IFindFluent <T, T> findFluent, PagedQueryBase query) { return(await findFluent.PaginateAsync(query.Page, query.Results)); }
public static Task <PagedResult <T> > PaginateAsync <T>(this IMongoQueryable <T> values, PagedQueryBase query) => values.PaginateAsync(query.Page, query.Results);
public static IQueryable <T> Limit <T>(this IQueryable <T> queryable, PagedQueryBase query) => queryable.Limit(query.Page, query.Results);
public static async Task <PagedResult <T> > PaginateAsync <T>(this IMongoQueryable <T> collection, PagedQueryBase query) => await collection.PaginateAsync(query.Page, query.Results);
/* 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)); }
public static IQueryable <T> Limit <T>(this IQueryable <T> collection, PagedQueryBase query) => collection.Limit(query.Page, query.PageSize);
public static IQueryable <T> Limit <T>(this IQueryable <T> collection, PagedQueryBase query) where T : BaseEntity => collection.Limit(query.Page, query.Results);
public static async Task <PagedResult <T> > PaginateAsync <T>(this IQueryable <T> collection, PagedQueryBase query) where T : BaseEntity => await collection.PaginateAsync(query.Page, query.Results);
public async Task <PagedResult <AdDto> > BrowseAsync(PagedQueryBase query) { var ad = await _adRepository.BrowseAsync(query); return(_mapper.Map <PagedResult <AdDto> >(ad)); }
public static PagedResult <T> Paginate <T>(this T[] values, PagedQueryBase query) => Paginate(values, query.Page, query.Results);
public static IMongoQueryable <Ad> FilterAds(this IMongoQueryable <Ad> collection, PagedQueryBase query) => collection.FilterAds(query.Filter);
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)); }
public async Task <PagedResult <Ad> > BrowseAsync(PagedQueryBase query) => await Ad.AsQueryable() .FilterAds(query) .OrderByDescending(x => x.AdDetails.CreateAt) .PaginateAsync(query);
public static IQueryable <T> Limit <T>(this IQueryable <T> collection, PagedQueryBase query) { return(collection.Limit(query.Page, query.Results)); }
///// <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() }); }
public static IMongoQueryable <T> Limit <T>(this IMongoQueryable <T> collection, PagedQueryBase query) => collection.Limit(query.Page, query.Results);
public static async Task <PagedResult <T> > PaginateAsync <T>(this IQueryable <T> queryable, PagedQueryBase query) => await queryable.PaginateAsync(query.Page, query.Results);