Пример #1
0
 /// <summary>
 /// Delete the specified Album from the storage and the collections
 /// </summary>
 /// <param name="albumToDelete"></param>
 /// <returns></returns>
 public static void DeleteAlbum(Album albumToDelete)
 {
     // No need to wait for the delete
     DbAccess.DeleteAsync(albumToDelete);
     AlbumCollection.Remove(albumToDelete);
     IdLookup.Remove(albumToDelete.Id);
 }
Пример #2
0
        public Track UpdateTrack(RawTrack track)
        {
            Track old;

            if (!_trackDict.TryGetValue(track.FullFilename, out old))
            {
                throw new ArgumentException(track.FullFilename + " was not found in library - use Add instead.", "track");
            }

            old.Title       = track.TrackTitle;
            old.Tracknumber = track.TrackNumberUnknown ? (int?)null : track.TrackNumber;

            Album album = _albums[track.AlbumTitle] ?? CreateAlbum(track.AlbumTitle, track.Year);

            if (album != old.Album)
            {
                old.Album.Tracks.Remove(old);
                if (old.Album.Tracks.Count == 0)
                {
                    _albums.Remove(old.Album);
                }

                old.Album = album;
                album.Tracks.Add(old);
            }
            else
            {
                album.Tracks.Reposition(old);
            }

            Artist artist = _artists[track.ArtistName] ?? CreateArtist(track.ArtistName);

            if (artist != old.Artist)
            {
                Artist oldArtist = old.Artist;
                old.Artist = artist;

                old.Album.Tracks.Remove(old);
                old.Album.Tracks.Add(old);
                if (oldArtist.Albums.Count == 0)
                {
                    _artists.Remove(oldArtist);
                }
            }

            return(old);
        }
Пример #3
0
 public IActionResult Delete(int albumID)
 {
     if (_albums.ContainsKey(albumID))
     {
         _albums.Remove(albumID, out Album a);
     }
     return(new OkResult());
 }
Пример #4
0
 /// <summary>
 /// Delete the specified Albums from the storage and the collections
 /// </summary>
 /// <param name="albumToDelete"></param>
 /// <returns></returns>
 public static void DeleteAlbums(IEnumerable <Album> albumsToDelete)
 {
     // No need to wait for the delete
     DbAccess.DeleteItemsAsync(albumsToDelete);
     foreach (Album albumToDelete in albumsToDelete)
     {
         AlbumCollection.Remove(albumToDelete);
         IdLookup.Remove(albumToDelete.Id);
     }
 }
Пример #5
0
        internal void RemoveAlbumIfNeeded(AlbumViewModel albumViewModel)
        {
            if (albumViewModel.Songs.Count == 0)
            {
                if (albumViewModel.Artist.Albums.Contains(albumViewModel))
                {
                    albumViewModel.Artist.Albums.Remove(albumViewModel);
                    RemoveArtistIfNeeded(albumViewModel.Artist);

                    AlbumCollection.Remove(albumViewModel, albumViewModel.SortName);
                    AlbumLookupMap.Remove(albumViewModel.AlbumId);

                    albumViewModel.IsBeingDeleted = true;

                    LibraryModel.Current.DeleteAlbum(albumViewModel.AlbumId);
                }
            }
        }
Пример #6
0
        private async void AllMusic_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                MusicCollection.AddRange(e.NewItems.Cast <LocalMusic>());
                // ArtistCollection.AddRange(e.NewItems.Cast<LocalMusic>());
                AlbumCollection.AddRange(e.NewItems.Cast <LocalMusic>());
                break;

            case NotifyCollectionChangedAction.Remove:
                foreach (LocalMusic item in e.OldItems)
                {
                    MusicCollection.Remove(item);
                    //  ArtistCollection.Remove(item);
                    AlbumCollection.Remove(item);
                }
                await ArtistCollection.AddRangeAsync(AllMusic.GroupBy(x => x.ArtistsName?.FirstOrDefault() ?? "未知艺术家").ToDictionary(x => x.Key, x => x.ToArray())
                                                     .Select(x =>
                                                             new LocalArtist
                {
                    Name        = x.Key,
                    PicPath     = x.Value.First().Id3Pic,
                    LocalMusics = x.Value
                }));

                break;

            case NotifyCollectionChangedAction.Replace:
                break;

            case NotifyCollectionChangedAction.Move:
                break;

            case NotifyCollectionChangedAction.Reset:
                MusicCollection.Clear();
                ArtistCollection.Clear();
                AlbumCollection.Clear();
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Пример #7
0
 internal void AlertAlbumNameChanged(AlbumViewModel albumViewModel, string oldName)
 {
     AlbumCollection.Remove(albumViewModel, oldName);
     AlbumCollection.Add(albumViewModel, albumViewModel.SortName);
 }