예제 #1
0
        public IList <AddToPlaylistDto> GetAddToPlaylists(int userId, int trackId)
        {
            if (userId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(userId));
            }
            if (trackId <= 0)
            {
                throw new ArgumentOutOfRangeException(nameof(trackId));
            }

            var track = _playlistRepository.GetById <Track>(trackId) ?? throw new ArgumentNullException(nameof(trackId));
            var user  = _playlistRepository.GetById <User>(userId) ?? throw new ArgumentNullException(nameof(userId));

            var addToPlaylistDtos = _playlistRepository.GetAddToPlaylists(user.Id);

            foreach (var dto in addToPlaylistDtos)
            {
                dto.Artwork         = _playlistRepository.GetArtwork(dto.PlaylistId).Value;
                dto.HasTrack        = _playlistRepository.IsTrackInPlaylist(track.Id, dto.PlaylistId);
                dto.CreatorUserName = user.UserName;
            }

            return(addToPlaylistDtos);
        }