public void Run()
        {
            while (true)
            {
                Console.WriteLine("");
                Console.WriteLine("Enter the country name to get the information. If you want to see the global information, type \"Global\". For the list of all countries type \"List\". To exit Covid-19 Statistics type \"Exit\": ");
                string userInput = Console.ReadLine();
                Console.WriteLine("");

                if (userInput == "Exit")
                {
                    return;
                }

                string content = string.Empty;
                using (var wc = new WebClient())
                {
                    content = wc.DownloadString("https://api.covid19api.com/summary");
                }
                CovidRoot summary = JsonSerializer.Deserialize <CovidRoot>(content);

                if (userInput.StartsWith("List", StringComparison.InvariantCultureIgnoreCase))
                {
                    userInput = userInput.Substring(4).TrimStart();
                    Console.WriteLine("Found countries: ");
                    foreach (var countryJson in summary.Countries)
                    {
                        if (countryJson.Country.StartsWith(userInput, StringComparison.InvariantCultureIgnoreCase))
                        {
                            Console.WriteLine(countryJson.Country);
                        }
                    }
                }
                else if (userInput.Equals("Global", StringComparison.InvariantCultureIgnoreCase))
                {
                    ShowCovidInfo("Global", summary.Global.NewConfirmed, summary.Global.TotalConfirmed, summary.Global.NewDeaths, summary.Global.TotalDeaths, summary.Global.NewRecovered, summary.Global.TotalRecovered);
                }
                else
                {
                    bool countryExists = false;

                    foreach (var countryJson in summary.Countries)
                    {
                        if (userInput.Equals(countryJson.Country, StringComparison.InvariantCultureIgnoreCase))
                        {
                            ShowCovidInfo(countryJson.Country, countryJson.NewConfirmed, countryJson.TotalConfirmed, countryJson.NewDeaths, countryJson.TotalDeaths, countryJson.NewRecovered, countryJson.TotalRecovered);
                            countryExists = true;
                        }
                    }

                    if (countryExists == false)
                    {
                        Console.WriteLine("Country does not exist. Type \"List\" to see the list of available countries.");
                    }
                }
            }
        }
Exemple #2
0
        public static async Task <string> GetDetail()
        {
            var    http        = new HttpClient();
            string urlGetCovid = "https://gw.vnexpress.net/cr/?name=tracker_coronavirus";
            var    response    = await http.GetAsync(urlGetCovid);

            var result = await response.Content.ReadAsStringAsync();

            CovidRoot covidRoot = JsonConvert.DeserializeObject <CovidRoot>(result);

            string temp = @"Tại Việt Nam, tổng số có: " + covidRoot.Data.DataData[0].TrackerTotalByDay.Cases + " ca nhiễm."
                          + " Số ca tử vong là: " + covidRoot.Data.DataData[0].TrackerTotalByDay.Deaths + " ca."
                          + " Số ca chữa khỏi là: " + covidRoot.Data.DataData[0].TrackerTotalByDay.Recovered + " ca.\n";
            var listProvince = covidRoot.Data.DataData[0].TrackerByProvince;

            temp += "========Thống kê theo tỉnh thành=======:\n";
            foreach (var provice in listProvince)
            {
                temp += @"-" + provice.Name + ": " + provice.Cases + " ca nhiễm. " + provice.Deaths + " ca tử vong. " + provice.Recovered + " ca chữa khỏi \n";
            }
            return(temp);
        }