public async Task <bool> InsertArtist(Artist artist) { try { if (artist == null) { return(false); } await using var entities = new DataIngestionContext(); if (entities.Artist.Any(o => o.ArtistId == artist.ArtistId)) { return(false); } await entities.Artist.AddAsync(artist).ConfigureAwait(true); var saveChanges = await entities.SaveChangesAsync().ConfigureAwait(true); if (saveChanges > 0) { _logger.LogInformation($"Saved {artist.Name} artistCollection."); return(true); } _logger.LogInformation("Saved 0 artist."); return(false); } catch (DbUpdateException sqlex) { _logger.LogError(sqlex.Message, sqlex.Message, artist); return(false); } }
public async Task <int> GetTotalRowsOfAlbums() { try { await using var entities = new DataIngestionContext(); entities.Database.SetCommandTimeout(300); var res = (from atc in entities.ArtistCollection join col in entities.Collection on atc.CollectionId equals col.CollectionId join clm in entities.CollectionMatch on atc.CollectionId equals clm.CollectionId select new { col.CollectionId, col.Name, col.ViewUrl, clm.Upc, col.OriginalReleaseDate, col.IsCompilation, col.LabelStudio, col.ArtworkUrl, //Lists= (from at in entities.Artist where at.ArtistId == atc.ArtistId select new {at.ArtistId, at.Name}).ToList() }).Count(); return(res); } catch (DbUpdateException sqlex) { _logger.LogError(sqlex.Message, sqlex.Message); return(0); } }
public async Task <List <Album> > GetAlbums(int skip, int take) { try { await using var entities = new DataIngestionContext(); entities.Database.SetCommandTimeout(300); var res = await(from atc in entities.ArtistCollection join col in entities.Collection on atc.CollectionId equals col.CollectionId join clm in entities.CollectionMatch on atc.CollectionId equals clm.CollectionId select new Album { AlbumId = col.CollectionId, Name = col.Name, ImageUrl = col.ViewUrl, Upc = clm.Upc, ReleaseDate = col.OriginalReleaseDate, IsCompilation = col.IsCompilation, Label = col.LabelStudio, Url = col.ArtworkUrl, IdAlbumArtist = atc.ArtistId }).Skip(skip).Take(take).ToListAsync().ConfigureAwait(true); return(res); } catch (DbUpdateException sqlex) { _logger.LogError(sqlex.Message, sqlex.Message); return(null); } }
public async Task <bool> InsertCollectionMatch(CollectionMatch collectionMatch) { try { if (collectionMatch == null) { return(false); } await using var entities = new DataIngestionContext(); if (entities.CollectionMatch.Any(o => o.CollectionId == collectionMatch.CollectionId)) { return(false); } await entities.CollectionMatch.AddAsync(collectionMatch); var saveChangesAsync = await entities.SaveChangesAsync().ConfigureAwait(true); if (saveChangesAsync > 0) { _logger.LogInformation("Saved 1 collectionMatch."); return(true); } _logger.LogInformation("Saved 0 collectionMatch."); return(false); } catch (DbUpdateException sqlex) { _logger.LogError(sqlex.Message, sqlex.Message, collectionMatch); return(false); } }
public async Task <List <AlbumArtist> > GetArtists(long artistId) { try { await using var entities = new DataIngestionContext(); entities.Database.SetCommandTimeout(300); var artists = (from at in entities.Artist where at.ArtistId == artistId select new AlbumArtist { AlbumArtistId = at.ArtistId, Name = at.Name }).Distinct().ToList(); return(artists); } catch (DbUpdateException sqlex) { _logger.LogError(sqlex.Message, sqlex.Message); return(null); } }