Пример #1
0
        private void WebApi()
        {
            //Creating webconnector
            wc = new WebConnector("https://api.covid19api.com/");

            var globalDataSets = (from s in _context.GlobalDataBase select s).ToList <GlobalDataBase>();

            DateTime today     = DateTime.Today;
            bool     existance = false;

            if (_context.GlobalDataBase.Any(record => record.DateDataBase == today))
            {
                existance = true;
            }
            if (!existance)
            {
                wc.SetGlobalSummary();
                GlobalData gd1 = JsonParser.ExtractSingleData <GlobalData>(wc.Connect(), "Global");
                _context.GlobalDataBase.Add(new GlobalDataBase {
                    TotalConfirmed = gd1.TotalConfirmed, DateDataBase = today
                });
                _context.SaveChanges();
            }

            if (existance)
            {
                Console.WriteLine("Todays data already in the data base.");
            }
            else if (!existance)
            {
                Console.WriteLine("Todays data added.");
            }

            Console.WriteLine("\n***Global data checked!***\n");
        }