void IPlaylistRequestHandler.SavePlaylistAs(string title, IEnumerable <PlaylistSong> songs)
        {
            //Let's just do the easy thing - kill the whole record and start over
            db.Playlists.RemoveRange(from playlist in db.Playlists
                                     where playlist.Title == title
                                     select playlist);

            Database.Playlist savePlaylist = new Database.Playlist()
            {
                Title = title
            };

            int index = 0;

            foreach (PlaylistSong song in songs)
            {
                PlaylistSong songCopy = new PlaylistSong()
                {
                    Number   = index++,
                    Song     = song.Song,
                    Weight   = song.Weight,
                    Title    = song.Title,
                    Playlist = savePlaylist
                };
                db.PlaylistSongs.Add(songCopy);

                foreach (PlaylistRecording recording in song.PlaylistRecordings)
                {
                    PlaylistRecording recordingCopy = new PlaylistRecording()
                    {
                        Title        = recording.Title,
                        Recording    = recording.Recording,
                        Weight       = recording.Weight,
                        PlaylistSong = songCopy
                    };

                    db.PlaylistRecordings.Add(recordingCopy);
                }
            }

            db.Playlists.Add(savePlaylist);
            db.SaveChanges();
        }
        IEnumerable <PlaylistSong> IPlaylistTransferRequestHandler.GetAlbumData(
            Album album,
            bool deep)
        {
            List <PlaylistSong> songData = new List <PlaylistSong>();

            try
            {
                db.Configuration.AutoDetectChangesEnabled = false;

                if (deep)
                {
                    foreach (Song song in
                             (from recording in album.Recordings
                              orderby recording.DiscNumber, recording.TrackNumber
                              select recording.Song).Distinct())
                    {
                        songData.Add(GetSongData(song: song));
                    }
                }
                else
                {
                    Database.Playlist currentPlaylist = GetCurrentPlaylist();

                    foreach (Recording recording in
                             from recording in album.Recordings
                             orderby recording.DiscNumber, recording.TrackNumber
                             select recording)
                    {
                        PlaylistSong newSong = new PlaylistSong(
                            song: recording.Song,
                            title: $"{recording.Artist.Name} - {recording.Song.Title}")
                        {
                            Playlist = currentPlaylist,
                            Weight   = recording.Weight
                        };

                        db.PlaylistSongs.Add(newSong);

                        PlaylistRecording newRecording = new PlaylistRecording(
                            recording: recording,
                            title: $"{recording.Artist.Name} - {recording.Album.Title} - {recording.Title}")
                        {
                            Weight = 1.0
                        };

                        newRecording.PlaylistSong = newSong;
                        db.PlaylistRecordings.Add(newRecording);

                        songData.Add(newSong);
                    }
                }
            }
            finally
            {
                db.Configuration.AutoDetectChangesEnabled = true;
            }

            db.SaveChanges();

            return(songData);
        }
예제 #3
0
 public PlayHistory(PlaylistSong song, PlaylistRecording recording)
 {
     this.song      = song;
     this.recording = recording;
 }
 void IPlaylistRequestHandler.Delete(PlaylistRecording playlistRecording)
 {
     db.PlaylistRecordings.Remove(playlistRecording);
 }
예제 #5
0
 public PlaylistRecordingViewModel(PlaylistRecording recording, PlaylistSongViewModel song)
     : base(recording, song)
 {
 }