Beispiel #1
0
        public ArtistModel GetByIdWithAlbums(long artistId)
        {
            var artist = _artistRepository.GetByIdWithAlbums(artistId);

            if (artist == null)
            {
                throw new Exception($"Artist did not found by id: {artistId}");
            }

            if (string.IsNullOrEmpty(artist.Description))
            {
                var           sourceId      = int.Parse(artist.SourceId);
                DiscogsClient discogsClient = CreateDiscogsClient();
                var           sourceArtist  = discogsClient.GetArtist(sourceId);

                artist.Description = sourceArtist.Profile;
                _artistRepository.Update(artist);
            }

            if (!artist.Albums.Any())
            {
                var sourceId      = int.Parse(artist.SourceId);
                var discogsClient = CreateDiscogsClient();

                var releasesForSave = new List <AlbumModel>();
                var sourceReleases  = discogsClient.GetArtistReleases(sourceId);
                foreach (var sourceRelease in sourceReleases.Releases)
                {
                    releasesForSave.Add(new AlbumModel
                    {
                        ArtistId = artist.Id,
                        Source   = SourceType.Discogs,
                        SourceId = sourceRelease.Id.ToString(),
                        Thumb    = sourceRelease.Thumb,
                        Title    = sourceRelease.Title,
                        Year     = sourceRelease.Year
                    }
                                        );
                }

                _albumRepository.SaveMany(releasesForSave);
            }

            return(_artistRepository.GetByIdWithAlbums(artistId));
        }
        public async Task GetArtist()
        {
            var res = await _DiscogsClient.GetArtist(224506);

            res.Should().NotBeNull();
        }