예제 #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
        public void DeleteById(int id)
        {
            EntityModel.Music music = _context.Musics.Find(id);

            if (music == null)
            {
                throw new ElementDeleteException <Music>(id, "Element to delete doesn't exist.");
            }

            try
            {
                _context.Musics.Remove(music);
                _context.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                throw new ElementDeleteException <Music>(id, "Unable to delete.", ex);
            }
        }
예제 #3
0
        public void DeleteById(int id)
        {
            var genre = _context.Genres.Include(g => g.Musics).Where(g => g.ID.Equals(id)).FirstOrDefault();

            if (genre == null)
            {
                throw new ElementDeleteException <Genre>(id, "Element to delete doesn't exist.");
            }

            if (genre.Musics.Count > 0)
            {
                throw new ElementDeleteException <Genre>(id, "Element to delete can't be deleted because it has at least one music associated with it.");
            }

            try
            {
                _context.Genres.Remove(genre);
                _context.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                throw new ElementDeleteException <Genre>(id, "Unable to delete", ex);
            }
        }
예제 #4
0
        public void DeleteById(int id)
        {
            EntityModel.Artist artist = _context.Artists.Include(a => a.Musics).Where(a => a.ID.Equals(id)).FirstOrDefault();

            if (artist == null)
            {
                throw new ElementDeleteException <Artist>(id, "Element to delete doesn't exist.");
            }

            if (artist.Musics.Count > 0)
            {
                throw new ElementDeleteException <Artist>(id, "Element to delete can't be deleted because it has at least one music associated with it.");
            }

            try
            {
                _context.Artists.Remove(artist);
                _context.SaveChanges();
            }
            catch (DbUpdateException ex)
            {
                throw new ElementDeleteException <Artist>(id, "Unable to delete", ex);
            }
        }
예제 #5
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"
                }
            };

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

            context.SaveChanges();
        }
예제 #6
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"
                }
            };

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

            context.SaveChanges();
        }