public CountryViewModel(string country, Covid19Model[] models) { Country = country; Models = models.Where(m => m.Confirmed > 0).ToArray(); if (Models.Length == 0) { Models = new Covid19Model[] { models.Last() }; } Summary = new Summary[] { new Summary() { Label = "TOTAL CONFIRMED", Count = TotalConfirmed, CountTextColor = Color.Coral }, new Summary() { Label = "ACTIVE CASES", Count = TotalActive, CountTextColor = Color.Coral }, new Summary() { Label = "TOTAL RECOVERIES", Count = TotalRecovered, CountTextColor = Color.FromHex("#00AEEF") }, new Summary() { Label = "TOTAL DEATHS", LabelBackgroundColor = Color.Red, LabelTextColor = Color.White, Count = TotalDeaths, CountBackgroundColor = Color.FromHex("#FCAC00"), CountTextColor = Color.Red } }; }
public Covid19Model Get(int airportId) { AirportModel airport = new AirportModel(); using (var connection = GetOpenConnection()) { airport = connection.Query <AirportModel>( @"select AirportId, AirportName, CityName, CountryName, AirportCode, Latitude, Longitude from Airports where AirportId = " + airportId).FirstOrDefault();//<= TODO: use parameters } Covid19ViewModel covidData = new Covid19ViewModel(); //TODO: add link to config string url = "https://covid-193.p.rapidapi.com/statistics?country=" + airport.CountryName; string answer; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; //TODO: add these to config request.Headers.Add("x-rapidapi-key: 7a9ab3b348mshfd960b72abb93f5p1b5cbajsn7b6c5b1140b7"); request.Headers.Add("x-rapidapi-host: covid-193.p.rapidapi.com"); request.Headers.Add("useQueryString: true"); using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) using (Stream stream = response.GetResponseStream()) using (StreamReader reader = new StreamReader(stream)) { answer = reader.ReadToEnd(); } covidData = JsonConvert.DeserializeObject <Covid19ViewModel>(answer); Covid19Model model = new Covid19Model(); covidData.Response.ForEach(c => model = new Covid19Model { CountryName = c.Country, Continent = c.Continent, Cases = c.Cases.Total == null ? 0 : (int)c.Cases.Total, NewCases = c.Cases.New == null ? 0 : int.Parse(c.Cases.New.Split('+')[1]), Deaths = c.Deaths.Total == null ? 0 : (int)c.Deaths.Total, NewDeaths = c.Deaths.New == null ? 0 : int.Parse(c.Deaths.New.Split('+')[1]), Recoverd = c.Cases.Recovered == null ? 0 : (int)c.Cases.Recovered, Tests = c.Tests.Total == null ? 0 : (int)c.Tests.Total, Updated = c.Time } ); return(model); }
public async Task <Covid19Model> Get(int airportId) { Covid19Model covidList = new Covid19Model(); string url = "https://localhost:44393/rapidapicovid19/" + airportId;//TODO: Move this link to config try { using (var httpClient = new HttpClient()) { using (var response = await httpClient.GetAsync(url)) { string apiResponse = await response.Content.ReadAsStringAsync(); covidList = JsonConvert.DeserializeObject <Covid19Model>(apiResponse); } } } catch (Exception e) { _logger.LogError("ERROR Getting Covid data from Worker: " + e.Message); } return(covidList); }