Exemplo n.º 1
0
        public async Task <PaggingResult <Song> > GetSongPage(IPaggingQuery query = null)
        {
            if (query == null)
            {
                query = new PaggingQuery();
            }

            var songsQuery = context.Songs
                             .Include(s => s.GenreSong)
                             .ThenInclude(s => s.Genre)
                             .Include(s => s.Album)
                             .AsNoTracking()
                             .AsQueryable();

            var totalItems = songsQuery.Count();

            var songsEntities = await songsQuery.ApplayPaging(query).ToArrayAsync();

            var paggingResult = new PaggingResult <Song>
            {
                CurrentPage = query.Page,
                PageSize    = query.PageSize,
                TotalItems  = totalItems,
                TResult     = mapper.Map <IEnumerable <Song> >(songsEntities)
            };

            return(paggingResult);
        }
Exemplo n.º 2
0
        public PaggingResult <Blob> GetBlobPage(IPaggingQuery query)
        {
            var blobsTable = context.Blobs
                             .AsNoTracking();

            // Apply Ordering
            blobsTable = blobsTable.OrderByDescending(b => b.CreatedDate);
            // Convert BlobTable to Blob
            var blobs = mapper.Map <IEnumerable <Blob> >(blobsTable);

            var totalItems        = blobs.Count();
            var blobsAfterPagging = blobs.ApplayPaging(query);
            var paggingResult     = new PaggingResult <Blob>
            {
                CurrentPage = query.Page,
                PageSize    = query.PageSize,
                TotalItems  = totalItems,
                TResult     = blobsAfterPagging
            };

            return(paggingResult);
        }
Exemplo n.º 3
0
 public static IEnumerable <T> ApplayPaging <T>(this IEnumerable <T> query, IPaggingQuery pagingParameter)
 {
     return(query
            .Skip(pagingParameter.PageSize * (pagingParameter.Page - 1))
            .Take(pagingParameter.PageSize));
 }