Exemplo 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();
        }
Exemplo n.º 2
0
        private void AddAlbum(ChinookDbContext context, int quantity)
        {
            var albumList = A.ListOf <Album>(quantity);

            for (int i = 1; i <= quantity; i++)
            {
                albumList[i - 1].AlbumId = i;
            }

            context.Album.AddRange(albumList);
            context.SaveChanges();
        }
        private void AddCustomers(ChinookDbContext context, int quantity)
        {
            var customerList = A.ListOf <Models.Customer>(quantity);

            for (int i = 1; i <= quantity; i++)
            {
                customerList[i - 1].CustomerId = i;
            }

            context.Customers.AddRange(customerList);
            context.SaveChanges();
        }
Exemplo n.º 4
0
        private void Add_Click(object sender, RoutedEventArgs e)
        {
            using (var db = new ChinookDbContext())
            {
                var dvd_media_type = new media_type {
                    Name = NewMediaType.Text
                };
                db.media_types.Add(dvd_media_type);
                db.SaveChanges();

                MediaTypes.ItemsSource = db.media_types.ToList();
            }
        }
Exemplo n.º 5
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);
                }
            }
        }
Exemplo n.º 6
0
        public void Display(string prompt, Action <ChinookDbContext, string> processor)
        {
            bool done      = false;
            var  new_value = "";

            while (!done)
            {
                base.Display();

                new_value = Input.ReadString(prompt);

                if (new_value != "")
                {
                    using (var db = new ChinookDbContext())
                    {
                        try
                        {
                            processor(db, new_value);
                            db.SaveChanges();
                            new_value = "";
                        }
                        catch (Exception ex)
                        {
                            Output.WriteLine(ex.Message);
                            if (ex.InnerException != null)
                            {
                                Output.WriteLine(ex.InnerException.Message);
                            }
                            Input.ReadString("Press Enter");
                        }
                    }
                    Output.Clear();
                }
                else
                {
                    done = true;
                }
            }
            Program.NavigateBack();
        }