Example #1
0
        public (int, List <SongDTO>) GetLibrarySongs(LibraryPageFilter filter)
        {
            //TODO OPTIMIZE QUERY PLEASEEEEE
            //TODO  correct filter and check if data is correct

            var query = from user in _context.Users
                        join lib in _context.Libraries on user.LibraryId equals lib.Id
                        join libSong in _context.LibrarySong on lib.Id equals libSong.LibraryId
                        join song in _context.Songs on libSong.SongId equals song.Id
                        join album in _context.Albums on song.AlbumId equals album.Id
                        join artist in _context.Artists on album.ArtistId equals artist.Id

                        where user.Id == filter.UserId &&
                        (song.Genre == filter.Genre || filter.Genre == null)
                        //&& ( IsYearInDecade(song.Year, filter.Decade))
                        && (song.PopularityRankingId == filter.PopularityRankingId || filter.PopularityRankingId == null) &&
                        (song.Genre == filter.Genre || filter.Genre == null)

                        select new SongDTO
            {
                Id     = song.Id,
                Name   = song.Name,
                Year   = song.Year,
                Album  = AlbumCoreConverter.ToShortDTO(album),
                Artist = ArtistCoreConverter.ToShortDTO(artist),
            };


            //int totalNumber = query.ToList().Count;
            int totalNumber = query.ToList().Where(song => IsYearInDecade(song.Year, filter.Decade)).ToList().Count;

            var songs = query.ToList().Where(song => IsYearInDecade(song.Year, filter.Decade)).Skip(filter.PageIndex * filter.PageSize).Take(filter.PageSize).ToList();

            return(totalNumber, songs);
        }
Example #2
0
 public List <ArtistDTO> GetArtists(ArtistsPageFilter filter)
 {
     return(_context.Artists.Include(a => a.Albums)
            .ThenInclude(alb => alb.Songs)
            .Where(a => a.Name.Contains(filter.SearchText))
            .Skip(filter.PageIndex * filter.PageSize)
            .Take(filter.PageSize)
            .Select(a => ArtistCoreConverter.ToLongDTO(a))
            .ToList());
 }