Ejemplo n.º 1
0
        public GenreViewModel(MusicLibrary library, Genre genre)
        {
            this.Name = genre.Name;
            this.genre = genre;
            this._filters = new FilterViewModel[0];
            this.library = library;
            library.PropertyChanged += library_PropertyChanged;

            if (library.Songs != null) LoadFilters();
        }
Ejemplo n.º 2
0
 public async Task<IEnumerable<Song>> GetSongsForGenre(Genre genre)
 {
     return await databaseConnection.QueryAsync<Song>("select song.* from Song song, SongGenre songGenre where song.Id = songGenre.SongId and songGenre.GenreId = ?", genre.Id);
 }
Ejemplo n.º 3
0
        private async Task AddAllRemainingSongs()
        {
            var newAlbums = songsToAdd.Select(p => new Tuple<string, string>(p.Album, p.AlbumArtist)).Distinct()
                .Where(p => p.Item1.Trim() != "" && !this.Albums.Any(q => q.Artist == p.Item2 && q.Name == p.Item1)).Select(p => new Album(p.Item1, p.Item2, this));
            foreach (var newAlbum in newAlbums) this.Albums.Add(newAlbum);
            var newArtists = songsToAdd.Select(p => p.AlbumArtist).Distinct(StringComparer.OrdinalIgnoreCase).Where(p => !this.Artists.Contains(p, StringComparer.OrdinalIgnoreCase));
            foreach (var newArtist in newArtists) this.Artists.Add(newArtist);

            foreach (var song in songsToAdd)
            {
                var exisitingSong = this.Songs.Where(p => p.FileName == song.FileName).FirstOrDefault();
                if (exisitingSong != null)
                {
                    song.Id = exisitingSong.Id;
                    await databaseConnection.UpdateAsync(song);
                    this.Songs.Remove(song);
                }
                else
                    await databaseConnection.InsertAsync(song);
                this.Songs.Add(song);

                await databaseConnection.ExecuteAsync("delete from SongGenre where SongId = ?", song.Id);
            }

            foreach (var genre in songGenresToAdd)
            {
                var genreInLibrary = this.Genres.FirstOrDefault(p => string.Equals(p.Name, genre.Item2, StringComparison.OrdinalIgnoreCase));
                if (genreInLibrary == null)
                {
                    genreInLibrary = new Genre(genre.Item2);
                    await databaseConnection.InsertAsync(genreInLibrary);
                    this.Genres.Add(genreInLibrary);
                }
                await databaseConnection.InsertAsync(new SongGenre(genre.Item1.Id, genreInLibrary.Id));
            }
            songsToAdd.Clear();
            songGenresToAdd.Clear();
        }