private async Task <bool> ImportSong(ImportSong song) { if (_context.Songs.Any(s => s.Name == song.Name)) { throw new Exception($"Unable to import song: '{song.Name}' already exists"); } var artist = _context.Artists.FirstOrDefault(a => a.Name == song.Artist); if (artist == null) { _logger.LogError($"Unable to import album: '{song.Album}' for artist '{song.Artist}'. No artist found with that name"); return(false); } Genre genre = null; if ((genre = _context.Genres.Local.Concat(_context.Genres).FirstOrDefault(g => g.Name == song.Genre)) == null) { genre = CreateGenre(song.Genre); } Album album = null; if (!string.IsNullOrEmpty(song.Album) && (album = GetAlbum(song.Album, song.Artist)) == null) { album = CreateAlbum(song.Album, _context.Artists.First(a => a.Name == song.Artist)); } await _context.Songs.AddAsync(new Song { Bpm = song.Bpm, Duration = song.Duration, Name = song.Name, Shortname = song.Shortname, SpotifyId = song.SpotifyId, Year = song.Year, AlbumId = album?.AlbumId, ArtistId = artist.ArtistId, GenreId = genre.GenreId, }); return(true); }
public bool ShouldImport(ImportSong song) => song.Genre.ToLowerInvariant().Contains("metal");