public async Task <IActionResult> PutScrapeRun(int id, ScrapeRun scrapeRun) { if (id != scrapeRun.Id) { return(BadRequest()); } _context.Entry(scrapeRun).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ScrapeRunExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <ActionResult <ScrapeRun> > PostScrapeRun(ScrapeRun scrapeRun) { _context.ScrapeRuns.Add(scrapeRun); await _context.SaveChangesAsync(); return(CreatedAtAction("GetScrapeRun", new { id = scrapeRun.Id }, scrapeRun)); }
public ScrapeRun ImportScrapeRun(string scrapeRunData) { var scrapeRun = new ScrapeRun(); return(scrapeRun); }
public void ImportScrape(cvScrapeData data) { if (data.heading.Contains("XX,XXX")) { return; } var existScrape = ctx.ScrapeRuns.FirstOrDefault(r => r.Heading.Trim() == data.heading.Trim()); if (existScrape != null) { return; } Console.WriteLine("updating..."); cvDataUtils.createGeolocationsFromScrapeFile(data); cvDataUtils.createCountriesFromScrapeFile(data); ScrapeRun scrape = new ScrapeRun() { CreateDate = DateTime.Now, Heading = data.heading, ScrapeDate = data.scrapeDate }; ctx.ScrapeRuns.Add(scrape); ctx.SaveChanges(); foreach (var geo in data.geoLocations) { foreach (var detail in geo.details) { var country = ctx.Countries.FirstOrDefault(r => r.Name == detail.country); if (country == null && detail.country != "TOTAL") { throw new Exception("country not found: " + detail.country); } if (detail.country == "TOTAL") { continue; } CountryStats stats = new CountryStats() { ScrapeRunId = scrape.Id, CountryId = country.Id, CreateDate = DateTime.Now, CaseCount = int.Parse(detail.cases.Trim().Replace(",", "").Replace("*", "")), DeathCount = int.Parse(detail.deaths.Trim().Replace(",", "").Replace("*", "")), Notes = detail.notes }; ctx.CountryStats.Add(stats); } } try { ctx.SaveChanges(); } catch (Exception ex) { throw ex; } }