/// <summary> /// The FetchSaveInformationToDatabase. /// </summary> /// <returns>The <see cref="Task"/>.</returns> private async Task FetchSaveInformationToDatabase() { //_dbContext.Database.ExecuteSqlRaw("TRUNCATE TABLE Config.Country"); using CoronaDbContext dbcontext = CoronaDbContext.GetContext(); dbcontext.Database.ExecuteSqlRaw("TRUNCATE TABLE Config.GlobalInfo"); (AllResults all, List <CountryResult> countries) = await GetAllInfo().ConfigureAwait(false); var mappedCountries = countries.Select(c => _mapper.Map <Countries>(c)).ToList(); await dbcontext.CoronaInfos.AddAsync(new CoronaInfo { Countries = mappedCountries, UpdateDate = DateTimeOffset.UtcNow }); await dbcontext.All.AddAsync(_mapper.Map <GlobalInfo>(all)).ConfigureAwait(false); await dbcontext.SaveChangesAsync().ConfigureAwait(false); await SendToSignalRClient(); }
/// <summary> /// Initializes a new instance of the <see cref="CoronaVirusService"/> class. /// </summary> /// <param name="hubContext">The hubContext<see cref="IHubContext{CoronaHub}" />.</param> /// <param name="mapper">The mapper<see cref="IMapper" />.</param> public CoronaVirusService(IHubContext <CoronaHub> hubContext, IMapper mapper) { _hubContext = hubContext; _mapper = mapper; _dbContext = CoronaDbContext.GetContext(); }