public bool RemoveArtist(Artist input) { if (input != null) { if (Artists.Count != 0) { if (Artists.Contains(input)) { Artists.Remove(input); return(true); } else { return(false); } } else { return(false); } } else { throw new ArgumentNullException(); } }
private void DeleteRelatedObjects(Track track) { var displaySameAsAlbumArtist = track.DisplayArtist.EqualsIgnoreCase(track.AlbumArtist); var albumArtist = Artists.FirstOrDefault(p => p.Name.EqualsIgnoreCase(track.AlbumArtist)); if (albumArtist != null) { albumArtist.Tracks.Remove(track); if (albumArtist.Tracks.Count == 0 && albumArtist.TracksThatAppearsIn.Count == 0) { Artists.Remove(albumArtist); } } DeleteAlbum(track, albumArtist); if (!displaySameAsAlbumArtist) { DeleteDisplayArtist(track); } DeleteSecondaryArtists(track); }
public async Task RemoveMediaFromCollectionAndDatabase(IMediaItem media) { if (media is TrackItem) { var trackItem = media as TrackItem; var trackDB = LoadTrackById(trackItem.Id); if (trackDB == null) { return; } musicDatabase.Remove(trackDB); var albumDB = LoadAlbum(trackItem.AlbumId); if (albumDB == null) { return; } var albumTracks = LoadTracksByAlbumId(albumDB.Id); if (!albumTracks.Any()) { Albums.Remove(Albums.FirstOrDefault(x => x.Id == trackItem.AlbumId)); musicDatabase.Remove(albumDB); } var artistDB = LoadArtist(trackItem.ArtistId); if (artistDB == null) { return; } var artistAlbums = LoadAlbums(artistDB.Id); if (!artistAlbums.Any()) { Artists.Remove(Artists.FirstOrDefault(x => x.Id == trackItem.ArtistId)); musicDatabase.Remove(artistDB); } await DispatchHelper.InvokeAsync(CoreDispatcherPriority.Normal, () => { Tracks.Remove(Tracks.FirstOrDefault(x => x.Path == trackItem.Path)); var playingTrack = Locator.MediaPlaybackViewModel.PlaybackService.Playlist.FirstOrDefault(x => x.Id == trackItem.Id); if (playingTrack != null) { Locator.MediaPlaybackViewModel.PlaybackService.Playlist.Remove(playingTrack); } }); } else if (media is VideoItem) { var videoItem = media as VideoItem; var videoDb = LoadVideoById(videoItem.Id); if (videoDb == null) { return; } videoDatabase.Remove(videoDb); Videos.Remove(Videos.FirstOrDefault(x => x.Path == videoItem.Path)); } }
public void DeleteObject(object entity) { if (entity is Genre) { Genres.Remove((Genre)entity); } if (entity is Artist) { Artists.Remove((Artist)entity); } if (entity is Album) { Albums.Remove((Album)entity); } if (entity is Cart) { Carts.Remove((Cart)entity); } if (entity is Order) { Orders.Remove((Order)entity); } if (entity is OrderDetail) { OrderDetails.Remove((OrderDetail)entity); } }
private void CheckForDeleted(ListBox lbSongsView, TreeView artistView, TreeView albumView) { var artists = new Dictionary <string, Artist>(Artists); foreach (var artist in artists) { if (artist.Value.Albums.Count == 0) { Artists.Remove(artist.Key); } else { var albums = new Dictionary <string, Album>(artist.Value.Albums); foreach (var album in albums) { if (album.Value.Songs.Count != 0) { continue; } artist.Value.Albums.Remove(album.Key); CheckForDeleted(lbSongsView, artistView, albumView); } } } lbSongsView.Items.Clear(); artistView.Nodes.Clear(); albumView.Nodes.Clear(); ShowAlbumsOnTreeView(albumView); ShowArtistsOnTreeView(artistView); ShowSongsOnControl(lbSongsView); }
public async Task DeleteSongAsync(Song song) { // remove it from artist and albums songs var artist = Artists.FirstOrDefault(p => p.Songs.Contains(song)); var album = Albums.FirstOrDefault(p => p.Songs.Contains(song)); if (album != null) { album.Songs.Remove(song); if (album.Songs.Count == 0) { await _sqlService.DeleteItemAsync(album); Albums.Remove(album); } } if (artist != null) { artist.Songs.Remove(song); if (artist.Songs.Count == 0) { await _sqlService.DeleteItemAsync(artist); Artists.Remove(artist); } } //good, now lets delete it from the db await _sqlService.DeleteItemAsync(song); Songs.Remove(song); }
public void DeleteSongArtist(int id) { var artist = Artists.SingleOrDefault(x => x.Id == id); if (artist != null) { Artists.Remove(artist); } this.SaveChanges(); }
private void DeleteDisplayArtist(Track track) { var displayArtist = Artists.FirstOrDefault(p => p.Name.EqualsIgnoreCase(track.DisplayArtist)); displayArtist.Tracks.Remove(track); if (displayArtist.TracksThatAppearsIn.Count == 0 && displayArtist.Tracks.Count == 0) { Artists.Remove(displayArtist); } }
public LikedArtistsViewModel() { DeleteCommand = new RelayCommand <LikedArtist>(async(artist) => { try { await LikedArtistsService.RemoveArtist(artist.Id); var msg = new MessageDialog($"Исполнитель {artist.Name} больше не находится в Ваших любимчиках!"); Artists.Remove(SelectArtist); Changed("Artists"); }catch (Exception e) { await ContentDialogService.Show(new ExceptionDialog("Невозможно удалить артиста", "Пока что нет возможности удалить, но скоро все будет хорооооошо :)", e)); } }); }
private void DeleteSecondaryArtists(Track track) { var artistAppearing = track.Artists.Split(';').Select(p => p.Trim()); foreach (var artist in artistAppearing .Where(p => !p.EqualsIgnoreCase(track.DisplayArtist) && !p.EqualsIgnoreCase(track.AlbumArtist)).Select(artistName => Artists.First(p => p.Name.EqualsIgnoreCase(artistName)))) { artist.TracksThatAppearsIn.Remove(track); if (artist.TracksThatAppearsIn.Count == 0 && artist.Tracks.Count == 0) { Artists.Remove(artist); } } }
private async void BtnDelete_Click(object sender, RoutedEventArgs e) { var artist = (Artist)((FrameworkElement)sender).DataContext; var ret = (bool)await DialogHost.Show(new ConfirmDialog("Remove Artist " + artist.Name + "?")); if (ret == true) { if (DatabaseOperations.DeleteArtist(artist) > 0) { Artists.Remove(artist); ToggleVisibility(); } else { await DialogHost.Show(new ErrorDialog("The artist has not been removed!")); } } }
public void RemoveSelectedSongs(TreeView tvArtistsView, ListBox lbSongsView, TreeView albumView) { var remove = tvArtistsView.SelectedNode; switch (remove.Level) { case 0: { var artist = (Artist)remove.Tag; Artists.Remove(artist.Name); } break; case 1: { var album = (Album)remove.Tag; var artist = (Artist)remove.Parent.Tag; Artists[artist.Name].Albums.Remove(album.Name); } break; case 2: { var song = (Song)remove.Tag; for (var i = 0; i < lbSongsView.Items.Count; i++) { lbSongsView.SetSelected(i, false); if (lbSongsView.Items[i] == song) { lbSongsView.SetSelected(i, true); } } RemoveSelectedSongs(lbSongsView, tvArtistsView, albumView); } break; default: return; } CheckForDeleted(lbSongsView, tvArtistsView, albumView); }
public DeletionResult DeleteSong(Song song, RealObservableCollection <GroupInfoList <Artist> > artistsList, RealObservableCollection <GroupInfoList <Album> > albumsList, RealObservableCollection <GroupInfoList <Song> > songsList) { GroupInfoList <Song> songList = MusicLibrary.GetItemGroup(songsList, song, a => a.SongTitle[0]); List <Song> songs; if (Songs.TryGetValue(song.Artist.ToLower() + "--" + song.Album.ToLower(), out songs)) { songList.Remove(song); songs.Remove(song); } songs = GetSongs(song.Artist, song.Album); if (songs.Count == 0) { Songs.Remove(song.Artist.ToLower() + "--" + song.Album.ToLower()); List <Album> albums; if (Albums.TryGetValue(song.Artist.ToLower(), out albums)) { Album album = albums.FirstOrDefault((a) => a.AlbumName == song.Album); albums.Remove(album); if (albums.Count == 0) { GroupInfoList <Album> albumList = MusicLibrary.GetItemGroup(albumsList, album, aa => aa.AlbumName[0]); Albums.Remove(song.Artist.ToLower()); albumList.Remove(album); Artist artist = Artists[song.Artist.ToLower()]; GroupInfoList <Artist> artistList = MusicLibrary.GetItemGroup(artistsList, artist, a => a.ArtistName[0]); Artists.Remove(song.Artist.ToLower()); artistList.Remove(artist); return(DeletionResult.Artist); } return(DeletionResult.Album); } } return(DeletionResult.Song); }
public async Task AddSongAsync(Song song, Tag tags = null) { var primaryArtist = (song.Album == null ? song.Artist : song.Album.PrimaryArtist) ?? new Artist { Name = "Unknown Artist", ProviderId = "autc.unknown" }; var artist = _inProgressArtists.Union(Artists).FirstOrDefault( entry => entry.ProviderId == primaryArtist.ProviderId || string.Equals(entry.Name, primaryArtist.Name, StringComparison.CurrentCultureIgnoreCase)); if (artist == null) { await _sqlService.InsertAsync(primaryArtist); _inProgressArtists.Add(primaryArtist); song.Artist = primaryArtist; song.ArtistId = primaryArtist.Id; if (song.Album != null) { song.Album.PrimaryArtistId = song.Artist.Id; song.Album.PrimaryArtist = song.Artist; } } else { song.Artist = artist; if (song.Album != null) { song.Album.PrimaryArtistId = artist.Id; song.Album.PrimaryArtist = artist; } } song.ArtistId = song.Artist.Id; if (song.Album == null) { song.Album = new Album { PrimaryArtistId = song.ArtistId, Name = song.Name, PrimaryArtist = song.Artist, ProviderId = "autc.single." + song.ProviderId }; } var album = _inProgressAlbums.Union(Albums).FirstOrDefault(p => p.ProviderId == song.Album.ProviderId); if (album != null) { song.Album = album; } else { await _sqlService.InsertAsync(song.Album); _inProgressAlbums.Add(song.Album); await _dispatcher.RunAsync(() => { var artwork = song.Artist.HasArtwork ? song.Artist.Artwork : _missingArtwork; song.Album.Artwork = artwork; song.Album.MediumArtwork = artwork; song.Album.SmallArtwork = artwork; }); if (tags != null && tags.Pictures != null && tags.Pictures.Length > 0) { var albumFilePath = string.Format(_artworkFilePath, song.Album.Id); Stream artwork = null; var image = tags.Pictures.FirstOrDefault(); if (image != null) { artwork = new MemoryStream(image.Data.Data); } if (artwork != null) { using (artwork) { try { var file = await StorageHelper.CreateFileAsync( albumFilePath, option : CreationCollisionOption.ReplaceExisting); using (var fileStream = await file.OpenAsync(FileAccess.ReadAndWrite)) { var bytes = tags.Pictures[0].Data.Data; await fileStream.WriteAsync(bytes, 0, bytes.Length); song.Album.HasArtwork = true; await _sqlService.UpdateItemAsync(song.Album); } } catch { // ignored } } } // set it if (song.Album.HasArtwork) { await _dispatcher.RunAsync( () => { var path = _localFilePrefix + albumFilePath; song.Album.Artwork = _bitmapFactory.CreateImage(new Uri(path)); if (ScaledImageSize == 0) { return; } song.Album.Artwork.SetDecodedPixel(ScaledImageSize); song.Album.MediumArtwork = _bitmapFactory.CreateImage(new Uri(path)); song.Album.MediumArtwork.SetDecodedPixel(ScaledImageSize / 2); song.Album.SmallArtwork = _bitmapFactory.CreateImage(new Uri(path)); song.Album.SmallArtwork.SetDecodedPixel(50); }); } } } song.AlbumId = song.Album.Id; if (string.IsNullOrEmpty(song.ArtistName)) { song.ArtistName = song.Artist.Name; } await _sqlService.InsertAsync(song); await _dispatcher.RunAsync( () => { if (!song.IsTemp) { var orderedAlbumSong = song.Album.Songs.ToList(); orderedAlbumSong.Add(song); orderedAlbumSong = orderedAlbumSong.OrderBy(p => p.TrackNumber).ToList(); var index = orderedAlbumSong.IndexOf(song); song.Album.Songs.Insert(index, song); var orderedArtistSong = song.Artist.Songs.ToList(); orderedArtistSong.Add(song); orderedArtistSong = orderedArtistSong.OrderBy(p => p.Name).ToList(); index = orderedArtistSong.IndexOf(song); song.Artist.Songs.Insert(index, song); #region Order artist album if (!song.Artist.Albums.Contains(song.Album)) { var orderedArtistAlbum = song.Artist.Albums.ToList(); orderedArtistAlbum.Add(song.Album); orderedArtistAlbum = orderedArtistAlbum.OrderBy(p => p.Name).ToList(); index = orderedArtistAlbum.IndexOf(song.Album); song.Artist.Albums.Insert(index, song.Album); } #endregion } _inProgressAlbums.Remove(song.Album); _inProgressArtists.Remove(song.Artist); if (!Albums.Contains(song.Album)) { Albums.Add(song.Album); } else if (song.Album.Songs.Count == 1) { // This means the album was added with a temp song // Have to remove and readd it to get it to show up Albums.Remove(song.Album); Albums.Add(song.Album); } if (!Artists.Contains(song.Artist)) { Artists.Add(song.Artist); } else if (song.Artist.Songs.Count == 1) { // This means the album was added with a temp song // Have to remove and readd it to get it to show up Artists.Remove(song.Artist); Artists.Add(song.Artist); } Songs.Add(song); }); }
public async Task DeleteSongAsync(Song song) { var queueSong = PlaybackQueue.FirstOrDefault(p => p.SongId == song.Id); if (queueSong != null) { await DeleteFromQueueAsync(queueSong); } // remove it from artist, albums and playlists songs var playlists = Playlists.Where(p => p.Songs.Count(pp => pp.SongId == song.Id) > 0).ToList(); foreach (var playlist in playlists) { var songs = playlist.Songs.Where(p => p.SongId == song.Id).ToList(); foreach (var playlistSong in songs) { await DeleteFromPlaylistAsync(playlist, playlistSong); } if (playlist.Songs.Count == 0) { await DeletePlaylistAsync(playlist); } } if (song.Album != null) { song.Album.Songs.Remove(song); // If the album is empty, make sure that is not being used by any temp song if (song.Album.Songs.Count == 0 && Songs.Count(p => p.AlbumId == song.AlbumId) < 2) { await _sqlService.DeleteItemAsync(song.Album); await _dispatcher.RunAsync( () => { Albums.Remove(song.Album); if (song.Artist != null) { song.Artist.Albums.Remove(song.Album); } }); } } if (song.Artist != null) { song.Artist.Songs.Remove(song); if (song.Artist.Songs.Count == 0 && Songs.Count(p => p.ArtistId == song.ArtistId) < 2) { await _sqlService.DeleteItemAsync(song.Artist); await _dispatcher.RunAsync( () => { Artists.Remove(song.Artist); }); } } // good, now lets delete it from the db await _sqlService.DeleteItemAsync(song); await _dispatcher.RunAsync(() => Songs.Remove(song)); }