Ejemplo n.º 1
0
        public void add_sample_data(ChinookDbContext db)
        {
            var digital_download = new media_type()
            {
                Name = "Digital Download"
            };
            var rock_genre = new genre()
            {
                Name = "Rock"
            };
            var new_artist = new artist()
            {
                Name = "Bob Sacamano"
            };
            var new_album = new album()
            {
                Title = "My stuff 2018", Artist = new_artist
            };
            var new_track = new track()
            {
                Name = "Bad Medicine", Album = new_album, Genre = rock_genre, MediaType = digital_download
            };
            var new_playlist = new playlist()
            {
                PlaylistId = 0, Name = "Test playlist"
            };
            var ref_playlist_track = new playlist_track()
            {
                playlist = new_playlist, track = new_track
            };

            new_playlist.tracks.Add(ref_playlist_track);
            db.playlist_tracks.Add(ref_playlist_track);
            db.SaveChanges();
        }
Ejemplo n.º 2
0
        private void add_sample_data_to_db()
        {
            try
            {
                using (var db = new ChinookDbContext())
                {
                    var playlist = db.playlists.Include("tracks").FirstOrDefault();

                    if (playlist == null)
                    {
                        var new_track = new track()
                        {
                            Name = "Bad Medicine"
                        };
                        var new_playlist = new playlist()
                        {
                            PlaylistId = 0, Name = "Test playlist"
                        };
                        var ref_playlist_track = new playlist_track()
                        {
                            playlist = new_playlist, track = new_track
                        };
                        new_playlist.tracks.Add(ref_playlist_track);
                        db.playlists.Add(new_playlist);
                        db.SaveChanges();

                        Tracks.ItemsSource = new_playlist.tracks;
                    }
                    else
                    {
                        Tracks.ItemsSource = playlist.tracks; // db.playlists.Include("tracks").ToList();
                    }
                }
            }
            catch (Exception ex)
            {
                System.Console.WriteLine("Error: \n" + ex.Message);
                if (ex.InnerException != null)
                {
                    System.Console.WriteLine("Inner Exception: \n" + ex.InnerException.Message);
                }
            }
        }