Пример #1
0
        public CasoCovid Salvar(CasoCovid caso)
        {
            if (_banco.CasosCovid.AsNoTracking().FirstOrDefault(x => x.Id == caso.Id) != null)
            {
                _banco.Update(caso);
            }
            else
            {
                _banco.Add(caso);
            }

            _banco.SaveChanges();

            return(caso);
        }
Пример #2
0
        private async Task <bool> SaveCovidDataIntoDb()
        {
            var covidParameters = new CovidParameters();
            var haveToSaveData  = false;

            if (_covidDbContext.CovidData.Count() == 0)
            {
                covidParameters.Uri = uriDayOneTotal;
                haveToSaveData      = true;
            }
            else
            {
                var lastSavedDate = _covidDbContext.CovidData.OrderByDescending(d => d.Date).First().Date;

                if (lastSavedDate < DateTime.Now)
                {
                    covidParameters.Uri  = uriByCountryTotal;
                    covidParameters.From = lastSavedDate.AddDays(1);
                    covidParameters.To   = DateTime.Now;
                    haveToSaveData       = true;
                }
            }

            if (haveToSaveData)
            {
                var covidData = await GetCovidAsync(covidParameters);

                if (covidData.Count > 0)
                {
                    covidData.OrderByDescending(d => d.Date);
                    _covidDbContext.AddRange(covidData);
                    _covidDbContext.SaveChanges();
                    return(true);
                }

                return(false);
            }

            return(false);
        }
Пример #3
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new CovidDbContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <CovidDbContext> >()))
            {
                // Look for any movies.
                if (context.DayRecords.Any())
                {
                    return;   // DB has been seeded
                }

                context.DayRecords.AddRange(
                    new DayRecord
                {
                    Date          = DateTime.Now,
                    NumVaccinated = 21000000,
                    NumDeaths     = 190,
                    NumRecovered  = 4450,
                    NewCases      = 5962,
                },
                    new DayRecord
                {
                    Date          = DateTime.Now.AddDays(-1),
                    NumVaccinated = 20000000,
                    NumDeaths     = 205,
                    NumRecovered  = 5230,
                    NewCases      = 7345,
                },
                    new DayRecord
                {
                    Date          = DateTime.Now.AddDays(-2),
                    NumVaccinated = 19000000,
                    NumDeaths     = 220,
                    NumRecovered  = 6534,
                    NewCases      = 9324,
                },
                    new DayRecord
                {
                    Date          = DateTime.Now.AddDays(-3),
                    NumVaccinated = 17000000,
                    NumDeaths     = 268,
                    NumRecovered  = 13224,
                    NewCases      = 19029,
                },
                    new DayRecord
                {
                    Date          = DateTime.Now.AddDays(-4),
                    NumVaccinated = 16000000,
                    NumDeaths     = 334,
                    NumRecovered  = 15343,
                    NewCases      = 18902,
                },
                    new DayRecord
                {
                    Date          = DateTime.Now.AddDays(-5),
                    NumVaccinated = 15000000,
                    NumDeaths     = 352,
                    NumRecovered  = 17354,
                    NewCases      = 23654,
                },
                    new DayRecord
                {
                    Date          = DateTime.Now.AddDays(-6),
                    NumVaccinated = 14000000,
                    NumDeaths     = 415,
                    NumRecovered  = 19324,
                    NewCases      = 26345,
                },
                    new DayRecord
                {
                    Date          = DateTime.Now.AddDays(-7),
                    NumVaccinated = 12000000,
                    NumDeaths     = 456,
                    NumRecovered  = 21354,
                    NewCases      = 26654,
                }
                    );


                context.SaveChanges();
            }
        }