Пример #1
0
 /// <summary>
 ///     Song information replacement
 /// </summary>
 /// <param name="song">Song to replace</param>
 public void ReplaceSong(Song song)
 {
     using (var context = new Context())
     {
         context.Tracks.Remove(context.Tracks.SingleOrDefault(t => t.PathOnUserPc == song.Path));
         context.SaveChanges();
         context.Artists.AddOrUpdate(a => a.ArtistName, new Artist
         {
             ArtistName = song.ArtistName
         });
         context.SaveChanges();
         context.Albums.AddOrUpdate(a => a.AlbumName,
             new Album
             {
                 AlbumName = song.Album
             });
         context.SaveChanges();
         context.Tracks.AddOrUpdate(t => t.PathOnUserPc,
             new Track
             {
                 TrackName = song.Title,
                 Duration = song.Duration,
                 PathOnUserPc = song.Path,
                 Album = context.Albums.SingleOrDefault(a => a.AlbumName == song.Album),
                 Artist = context.Artists.FirstOrDefault(a => a.ArtistName == song.ArtistName)
             });
         context.SaveChanges();
         DBChanged?.Invoke();
     }
 }
Пример #2
0
 /// <summary>
 ///     Uploading song list to the DB
 /// </summary>
 /// <param name="list">Song list to upload</param>
 public void LoadToDb(IEnumerable<Song> list)
 {
     using (var context = new Context())
     {
         foreach (var song in list)
         {
             context.Artists.AddOrUpdate(a => a.ArtistName, new Artist
             {
                 ArtistName = song.ArtistName
             });
             context.SaveChanges();
             context.Albums.AddOrUpdate(a => a.AlbumName,
                 new Album
                 {
                     AlbumName = song.Album
                 });
             context.SaveChanges();
             context.Tracks.AddOrUpdate(t => t.PathOnUserPc, new Track
             {
                 TrackName = song.Title,
                 Duration = song.Duration,
                 PathOnUserPc = song.Path,
                 Album = context.Albums.SingleOrDefault(a => a.AlbumName == song.Album),
                 Artist = context.Artists.FirstOrDefault(a => a.ArtistName == song.ArtistName)
             });
             context.SaveChanges();
         }
     }
     DBChanged?.Invoke();
 }
Пример #3
0
 /// <summary>
 ///     Deleting song
 /// </summary>
 /// <param name="obj">Song to delete</param>
 public void RemoveSongFromDb(Song obj)
 {
     using (var context = new Context())
     {
         var removed = context.Tracks.FirstOrDefault(t => t.PathOnUserPc == obj.Path);
         context.Tracks.Remove(removed);
         context.SaveChanges();
         DBChanged?.Invoke();
     }
 }