public async Task <IActionResult> GetResultsAsync(QuestionFormInfoReq req) { CovidStatisticsList covidStatistics = await GetStatisticsAsync(); TodayCases todayCases = await GetTodaysCasesAsync(); StatisticsResult stats = await CovidTestAsync(req); TodayAndGeneralStatistics todayAndGeneralStatistics = new TodayAndGeneralStatistics { CovidGeneral = covidStatistics, CovidToday = todayCases, statisticsRes = stats }; return(View(todayAndGeneralStatistics)); }
private async Task <CovidStatisticsList> GetStatisticsAsync() { System.Net.ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); }; var baseAddress = new Uri("https://api.covid19api.com/"); using (var httpClient = new HttpClient { BaseAddress = baseAddress }) { httpClient.DefaultRequestHeaders.TryAddWithoutValidation("accept", "application/json"); using (var response = await httpClient.GetAsync("dayone/country/bosnia-and-herzegovina")) { string responseData = await response.Content.ReadAsStringAsync(); CovidStatistics[] covidStatistics = JsonConvert.DeserializeObject <CovidStatistics[]>(responseData); List <CovidStatistics> listCovid = new List <CovidStatistics>() { }; for (int i = covidStatistics.Count() - 1; i > covidStatistics.Count() - 31; i--) { listCovid.Add(covidStatistics[i]); } listCovid.Reverse(); CovidStatisticsList covid = new CovidStatisticsList() { ListOfCovidStatistics = listCovid, }; return(covid); } } }