示例#1
0
        private static void AddMusics(MusicalContext context)
        {
            if (context.Musics.Any())
            {
                return;
            }

            var musics = new Music[]
            {
                new Music {
                    Name = "Echoes", ArtistID = 1, GenreID = 1
                },
                new Music {
                    Name = "Time", ArtistID = 1, GenreID = 1
                },
                new Music {
                    Name = "Astronomy Domine", ArtistID = 1, GenreID = 6
                },
                new Music {
                    Name = "Everything She Wants", ArtistID = 2, GenreID = 2
                },
                new Music {
                    Name = "I'm Your Man", ArtistID = 2, GenreID = 2
                },
                new Music {
                    Name = "Back In Black", ArtistID = 3, GenreID = 4
                },
                new Music {
                    Name = "Master Of Puppets", ArtistID = 4, GenreID = 3
                },
                new Music {
                    Name = "Call Of Ktulu", ArtistID = 4, GenreID = 3
                },
                new Music {
                    Name = "Enter Sandman", ArtistID = 4, GenreID = 4
                },
                new Music {
                    Name = "Love Me Do", ArtistID = 5, GenreID = 5
                },
                new Music {
                    Name = "Strawberry Fields Forever", ArtistID = 5, GenreID = 5
                },
                new Music {
                    Name = "A Day In Life", ArtistID = 5, GenreID = 5
                },
                new Music {
                    Name = "Good Vibrations", ArtistID = 6, GenreID = 5
                },
                new Music {
                    Name = "Sloop John B", ArtistID = 6, GenreID = 5
                }
            };

            foreach (Music m in musics)
            {
                context.Musics.Add(m);
            }

            context.SaveChanges();
        }
示例#2
0
        private void BtnDiskDelete_Click(object sender, RoutedEventArgs e)
        {
            DiskView diskView = new DiskView();

            diskView = musicListView.SelectedItem as DiskView;

            Storage storage = db.Storages.FirstOrDefault(s => s.DiskId == diskView.DiskId);

            db.Storages.Remove(storage);
            Price price = db.Prices.FirstOrDefault(p => p.DiskId == diskView.DiskId);

            db.Prices.Remove(price);
            if (db.DiscountDisks.Where(d => d.DiskId == diskView.DiskId).Count() > 0)
            {
                DiscountDisk discount = db.DiscountDisks.FirstOrDefault(d => d.DiskId == diskView.DiskId);
                db.DiscountDisks.Remove(discount);
            }

            Disk disk = db.Disks.FirstOrDefault(d => d.Id == diskView.DiskId);

            db.Disks.Remove(disk);
            db.SaveChanges();
            LoadDisks();
        }
示例#3
0
        private static void AddGenre(MusicalContext context)
        {
            if (context.Genres.Any())
            {
                return;
            }

            var genres = new Genre[]
            {
                new Genre {
                    Name = "Prog Rock"
                },
                new Genre {
                    Name = "Pop"
                },
                new Genre {
                    Name = "Metal"
                },
                new Genre {
                    Name = "Hard Rock"
                },
                new Genre {
                    Name = "Pop Rock"
                },
                new Genre {
                    Name = "Acid Rock"
                },
                new Genre {
                    Name = "KPop"
                }
            };

            foreach (Genre g in genres)
            {
                context.Genres.Add(g);
            }

            context.SaveChanges();
        }
示例#4
0
        private static void AddArtists(MusicalContext context)
        {
            if (context.Artists.Any())
            {
                return;
            }

            var artists = new Artist[]
            {
                new Artist {
                    Name = "Pink Floyd"
                },
                new Artist {
                    Name = "Wham!"
                },
                new Artist {
                    Name = "AC/DC"
                },
                new Artist {
                    Name = "Metallica"
                },
                new Artist {
                    Name = "The Beatles"
                },
                new Artist {
                    Name = "The Beach Boys"
                },
                new Artist {
                    Name = "Oasis"
                }
            };

            foreach (Artist a in artists)
            {
                context.Artists.Add(a);
            }

            context.SaveChanges();
        }
示例#5
0
 public void Create(T obj)
 {
     _db.Set <T>().Add(obj);
     _db.SaveChanges();
 }