Exemplo n.º 1
0
        public PagenatedResult GetPagenatedList(PagenagedQueryArgs args)
        {
            var query = this.Dbc.GetGenreQuery();

            if (!string.IsNullOrEmpty(args.FilterText))
            {
                query = query
                        .Where(e => e.LowerName.Contains(args.FilterText.ToLower()));
            }

            var totalLength = query.Count();

            query = query.OrderBy(e => e.LowerName);

            if (args.Page != null)
            {
                query = query
                        .Skip(((int)args.Page - 1) * this.PageLength)
                        .Take(this.PageLength);
            }


            var array = query.ToArray();

            var result = new PagenatedResult()
            {
                TotalLength  = totalLength,
                ResultLength = array.Length,
                ResultPage   = args.Page,
                ResultList   = array
            };

            return(result);
        }
Exemplo n.º 2
0
        public async Task <PagenatedResult> GetPagenatedList(PagenagedQueryArgs args)
        {
            var query = (IQueryable <Album>) this.Dbc.Albums
                        .Include(e => e.GenreAlbums)
                        .Include(e => e.ArtistAlbums)
                        .ThenInclude(e2 => e2.Artist);

            if (args.GenreIds != null && 0 < args.GenreIds.Length)
            {
                query = query
                        .Where(e => e.GenreAlbums.Any(e2 => args.GenreIds.Contains(e2.GenreId)));
            }

            if (args.ArtistIds != null && 0 < args.ArtistIds.Length)
            {
                query = query
                        .Where(e => e.ArtistAlbums.Any(e2 => args.ArtistIds.Contains(e2.ArtistId)));
            }

            if (!string.IsNullOrEmpty(args.FilterText))
            {
                query = query
                        .Where(e => e.LowerName.Contains(args.FilterText.ToLower()));
            }

            var ordered = query
                          .OrderBy(e => e.ArtistAlbums.Min(e2 => e2.Artist.LowerName))
                          .ThenBy(e => e.Year)
                          .ThenBy(e => e.LowerName);

            var totalLength = ordered.Count();

            var albums = (args.Page != null)
                ? ordered
                         .Skip(((int)args.Page - 1) * this.PageLength)
                         .Take(this.PageLength)
                         .ToList()
                : ordered
                         .ToList();

            var albumTracksList = await this.GetList(albums);

            var result = new PagenatedResult()
            {
                TotalLength  = totalLength,
                ResultLength = albums.Count(),
                ResultPage   = args.Page,
                ResultList   = albumTracksList.ToArray()
            };

            return(result);
        }