Ejemplo n.º 1
0
 private void SaveChanges()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         dbContext.Attach(this.data);
         dbContext.SaveChanges();
     }
 }
Ejemplo n.º 2
0
 private void LoadAlbums()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         dbContext
         .Attach(this.data)
         .Collection(artist => artist.Albums)
         .Load();
     }
 }
Ejemplo n.º 3
0
 private void LoadSongs()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         dbContext
         .Attach(this.data)
         .Collection(album => album.Songs)
         .Load();
     }
 }
Ejemplo n.º 4
0
 private bool LoadFavorite()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         return(dbContext
                .Attach(this.data)
                .Collection(artist => artist.Albums)
                .Query()
                .GroupJoin(dbContext.Songs, album => album.AlbumId, song => song.SongId, (album, songs) => songs)
                .All(songs => songs.All(song => song.Favorite)));
     }
 }
Ejemplo n.º 5
0
 private bool LoadFavorite()
 {
     using (MusicLibraryContext dbContext = new MusicLibraryContext())
     {
         return(this.anySongs &&
                dbContext
                .Attach(this.data)
                .Collection(album => album.Songs)
                .Query()
                .All(song => song.Favorite));
     }
 }
Ejemplo n.º 6
0
        private void FavoriteAllSongs(bool favorite)
        {
            this.LoadSongs();

            using (MusicLibraryContext dbContext = new MusicLibraryContext())
            {
                foreach (Song song in this.data.Songs)
                {
                    song.Favorite = favorite;

                    dbContext
                    .Attach(song)
                    .Property(_song => _song.Favorite)
                    .IsModified = true;
                }

                dbContext.SaveChanges();
            }
        }
Ejemplo n.º 7
0
        private void FavoriteAllSongs(bool favorite)
        {
            this.LoadAlbums();

            using (MusicLibraryContext dbContext = new MusicLibraryContext())
            {
                foreach (Album album in this.data.Albums)
                {
                    List <Song> songs = dbContext.Songs.Where(song => song.AlbumId == album.AlbumId).ToList();

                    foreach (Song song in songs)
                    {
                        song.Favorite = favorite;

                        dbContext
                        .Attach(song)
                        .Property(_song => _song.Favorite)
                        .IsModified = true;
                    }
                }

                dbContext.SaveChanges();
            }
        }