Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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()));
        }
Ejemplo n.º 3
0
        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
            });
        }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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
            });
        }
Ejemplo n.º 6
0
 public Task <Page <BlogStory> > GetPageWithTagsAsync(BlogStoryQuery query,
                                                      CancellationToken cancel = default)
 {
     return(_blogStoryRepository.GetPageWithTagsAsync(query, cancel));
 }
Ejemplo n.º 7
0
 private IQueryable <BlogStory> ExtendAndOrderQuery(IQueryable <BlogStory> dataQuery,
                                                    BlogStoryQuery query)
 {
     dataQuery = ExtendQuery(dataQuery, query);
     return(OrderQuery(dataQuery, query));
 }