Beispiel #1
0
        private async Task ImportSeriesDetails()
        {
            for (var index = 0; index < _importSeriesIds.Count; index++)
            {
                var seriesId = _importSeriesIds.ElementAt(index);

                var seriesJson = await _movieDbApi.GetSeriesDetails(seriesId);

                if (seriesJson != null)
                {
                    var seriesFromImport = await _movieDbDomainConverter.ConvertToSeries(seriesJson);

                    var seriesFromDb = await _tvSeriesContext
                                       .Series
                                       .Where(x => x.MovieDbId == seriesId)
                                       .FirstOrDefaultAsync();

                    var poster = await _movieDbApi.GetImage(seriesFromImport.PosterName);

                    seriesFromImport.PosterContent = poster;

                    await _movieDbImportServiceDbHelper.AddOrUpdate(seriesFromDb, seriesFromImport);

                    // Import seasons too because it is in seriesJson already
                    // get series id for season

                    var seriesDbId = await _tvSeriesContext
                                     .Series
                                     .Where(x => x.MovieDbId == seriesId)
                                     .Select(x => x.Id)
                                     .FirstOrDefaultAsync();

                    var seasons = _movieDbDomainConverter.ConvertToSeason(seriesJson, seriesDbId);

                    foreach (var seasonFromImport in seasons)
                    {
                        var seasonFromDb = await _tvSeriesContext
                                           .Seasons
                                           .Where(x => x.MovieDbId == seasonFromImport.MovieDbId)
                                           .FirstOrDefaultAsync();

                        await _movieDbImportServiceDbHelper.AddOrUpdate(seasonFromDb, seasonFromImport);
                    }
                }
                else
                {
                    _logger.LogInformation("Series with MovieDbId [{0}] not found", seriesId);
                }
            }
        }