public async Task DeleteFromPlaylistAsync(Playlist playlist, PlaylistSong songToRemove) { if (songToRemove.NextId != 0) { var nextSong = playlist.LookupMap[songToRemove.NextId]; nextSong.PrevId = songToRemove.PrevId; await _sqlService.UpdateItemAsync(nextSong); } if (songToRemove.PrevId != 0) { var prevSong = playlist.LookupMap[songToRemove.PrevId]; prevSong.NextId = songToRemove.NextId; await _sqlService.UpdateItemAsync(prevSong); } await _sqlService.DeleteItemAsync(songToRemove); await _dispatcher.RunAsync(() => playlist.Songs.Remove(songToRemove)); }
public async Task AddToPlaylistAsync(Playlist playlist, Song song) { var tail = playlist.Songs.LastOrDefault(); // Create the new queue entry var newSong = new PlaylistSong { SongId = song.Id, NextId = 0, PrevId = tail == null ? 0 : tail.Id, Song = song, PlaylistId = playlist.Id }; // Add it to the database await _sqlService.InsertAsync(newSong); if (tail != null) { // Update the next id of the previous tail tail.NextId = newSong.Id; await _sqlService.UpdateItemAsync(tail); } // Add the new queue entry to the collection and map playlist.Songs.Add(newSong); playlist.LookupMap.TryAdd(newSong.Id, newSong); }
public Task DeleteFromPlaylistAsync(Playlist playlist, PlaylistSong songToRemove) { throw new NotImplementedException(); }