public Task <List <BlogStory> > GetAsync(BlogStoryQuery query, CancellationToken cancel = default) { var dataQuery = ExtendAndOrderQuery(Entities, query); return(dataQuery.Skip(query.Offset) .Take(query.Limit) .ToListAsync(cancel)); }
private IQueryable <BlogStory> OrderQuery(IQueryable <BlogStory> dataQuery, BlogStoryQuery query) { var orderParameters = query.OrderParameters; if (orderParameters.IsEmpty()) { return(dataQuery); } return(dataQuery.ApplyOrder(orderParameters.Select(x => (new BlogStoriesOrderMapping(x.orderField).Base, x.isAsc)) .ToList())); }
public async Task <Page <BlogStory> > GetPageAsync(BlogStoryQuery query, CancellationToken cancel = default) { var dataQuery = ExtendQuery(Entities, query); var totalCount = await dataQuery.CountAsync(cancel); dataQuery = OrderQuery(dataQuery, query); var stories = await dataQuery.Skip(query.Offset) .Take(query.Limit) .ToListAsync(cancel); return(new Page <BlogStory> { TotalCount = totalCount, PageSize = query.Limit, Items = stories }); }
private IQueryable <BlogStory> ExtendQuery(IQueryable <BlogStory> dataQuery, BlogStoryQuery query) { if (query.IsPublished.HasValue) { dataQuery = query.IsPublished.Value ? dataQuery.Where(x => x.PublishedDate.HasValue) : dataQuery.Where(x => !x.PublishedDate.HasValue); } if (query.StoriesIds.IsNotEmpty()) { dataQuery = dataQuery.Where(x => query.StoriesIds.Contains(x.Id)); } if (query.TagId.HasValue) { dataQuery = dataQuery.Where(x => x.BlogStoryTags.Any(t => t.TagId == query.TagId)); } return(dataQuery); }
public async Task <Page <BlogStory> > GetPageWithTagsAsync(BlogStoryQuery query, CancellationToken cancel = default) { IQueryable <BlogStory> dataQuery = Entities.Include(x => x.BlogStoryTags) .ThenInclude(x => x.Tag); dataQuery = ExtendQuery(dataQuery, query); var totalCount = await dataQuery.CountAsync(cancel); dataQuery = OrderQuery(dataQuery, query); var stories = await dataQuery.Skip(query.Offset) .Take(query.Limit) .ToListAsync(cancel); return(new Page <BlogStory> { TotalCount = totalCount, PageSize = query.Limit, Items = stories }); }
public Task <Page <BlogStory> > GetPageWithTagsAsync(BlogStoryQuery query, CancellationToken cancel = default) { return(_blogStoryRepository.GetPageWithTagsAsync(query, cancel)); }
private IQueryable <BlogStory> ExtendAndOrderQuery(IQueryable <BlogStory> dataQuery, BlogStoryQuery query) { dataQuery = ExtendQuery(dataQuery, query); return(OrderQuery(dataQuery, query)); }