public List <CovidLocations_USDADto> FetchUSLocationsFromAPI() { WebRequest request = WebRequest.Create(configuration.GetSection("AppSettings")["covidConfirmedCases_USAPI"]); request.Method = "GET"; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader readerStream = new StreamReader(dataStream); Console.WriteLine(((HttpWebResponse)response).StatusDescription); string responseFromServer = readerStream.ReadToEnd(); response.Close(); TextReader reader = new StringReader(responseFromServer); CsvReader csvReader = new CsvReader(reader, CultureInfo.InvariantCulture); dynamic records = csvReader.GetRecords <dynamic>(); List <CovidLocations_USBLDto> bALRecords = new List <CovidLocations_USBLDto>(); foreach (var rec in records) { CovidLocations_USBLDto location = new CovidLocations_USBLDto(); foreach (KeyValuePair <string, object> locationInRecord in rec) { if (locationInRecord.Key == "Admin2") { location.County = (string)locationInRecord.Value; } if (locationInRecord.Key == "Province_State") { location.State = (string)locationInRecord.Value; } if (locationInRecord.Key == "Country_Region") { location.Country = (string)locationInRecord.Value; } if (locationInRecord.Key == "Combined_Key") { location.Combined_Key = (string)locationInRecord.Value; } if (locationInRecord.Key == "Lat") { location.Lat = Convert.ToDouble(locationInRecord.Value); } if (locationInRecord.Key == "Long_") { location.Long = Convert.ToDouble(locationInRecord.Value); } } bALRecords.Add(location); } var dALRecords = Utils.Utilities.MapUSLocationsBLDTOtoDADTO(bALRecords); return(dALRecords); }
public static CovidLocations_USDADto ToUSLocationsDADto(this CovidLocations_USBLDto rec) { return(new CovidLocations_USDADto { County = rec.County, State = rec.State, Country = rec.Country, Combined_Key = rec.Combined_Key, Lat = rec.Lat, Long = rec.Long }); }