Beispiel #1
0
        static public void Add()
        {
            using var db = new AppDbContext();
            {
                int number = 332;
                number++;

                string Choice = Convert.ToString(number);
                Console.WriteLine("Please enter the name of the city");
                cityname = Console.ReadLine();
                Console.WriteLine("Please indicate population count");
                pop = Console.ReadLine();

                var city = new MyCity
                {
                    Name       = cityname,
                    Population = Convert.ToInt32(pop),
                    //id = number,
                    Date = date
                };
                //MyCity newCity = new MyCity(cityname, Convert.ToInt32(pop), date);
                db.Cities.Add(city);
                db.SaveChanges();

                listOfCities.Add(city);
            }
        }
Beispiel #2
0
        static private void ImportData(string pathToFile, string date)
        {
            using var db = new AppDbContext();
            //Get all lines from the file
            lines = File.ReadAllLines(pathToFile);
            //Store information about cities
            foreach (var line in lines.Skip(1))
            {
                String a = line.Replace("\"", "");

                string[] nums = a.Split(new char[] { ',' });
                var      city = new MyCity
                {
                    Name       = nums[1],
                    Population = Convert.ToInt32(nums[11]),
                    Cases      = Convert.ToInt32(nums[2]),
                    Deaths     = Convert.ToInt32(nums[5]),
                    Tested     = Convert.ToInt32(nums[8]),
                    Date       = date
                };
                db.Cities.Add(city);
                // MyCity city = new MyCity(nums[1], Convert.ToInt32(nums[11]), Convert.ToInt32(nums[2]), Convert.ToInt32(nums[5]), Convert.ToInt32(nums[8]), date);
                listOfCities.Add(city);
            }
            db.SaveChanges();
        }
Beispiel #3
0
        static void displayInformationAboutCity(int cityIndex)
        {
            if (cityIndex >= 332)
            {
                MyCity city = listOfCities[cityIndex];
                Console.Write(city.Name);
                Console.Write("(Population: ");
                Console.Write(city.Population);
                Console.WriteLine(")");
            }
            else
            {
                string nameOfCity = listOfCities[cityIndex].Name;
                Console.WriteLine($"Local COVID - {nameOfCity}(Population: {listOfCities[cityIndex].Population})");
                Console.WriteLine("Date\t\tCases\tDeaths\tTested");

                foreach (var city in listOfCities)
                {
                    if (city.Name.Equals(nameOfCity))
                    {
                        Console.WriteLine($"{city.Date}\t{city.Cases}\t{city.Deaths}\t{city.Tested}");
                    }
                }
            }
        }