Example #1
0
        private static async Task SeedGenres(IeemdbDbContext ctx, ITheMovieDb api, ILogger logger)
        {
            if (await ctx.Genres.AnyAsync())
            {
                return;
            }

            var genres = await api.GetGenres();

            var genreEntities = genres.genres.Select(x => new Genre {
                Name = x.name, TmdbId = x.id,
            }).ToList();

            ctx.Genres.AddRange(genreEntities);
        }
Example #2
0
 public MovieSyncingService(
     IServiceScopeFactory factory,
     ITheMovieDb tmdb,
     ILogger <MovieSyncingService> logger,
     IOptions <ServiceDurations> durations)
 {
     this.factory     = factory;
     tmdbApi          = tmdb;
     serviceDurations = durations.Value;
     this.logger      = logger;
     timer            = new Timer(
         Trigger,
         null,
         TimeSpan.Zero,
         TimeSpan.FromSeconds(serviceDurations.DatabaseSeedingInMinutes));
 }
Example #3
0
        private static async Task SeedCountries(IeemdbDbContext ctx, ITheMovieDb api, ILogger logger)
        {
            if (await ctx.Countries.AnyAsync())
            {
                return;
            }

            try
            {
                var countries = await api.GetCountries();

                var countryEntities = countries.Select(x => new Country {
                    Iso = x.iso_3166_1, Name = x.english_name
                })
                                      .ToList();
                ctx.Countries.AddRange(countryEntities);
            }
            catch (ApiException e)
            {
                logger.LogCritical(e, "Unhandled exception caught: {Message}", e.Message);
            }
        }