Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            DbClient client              = new DbClient(new MongoClient());
            var      citizenService      = new CitizenService(Client);
            var      municipalityService = new MunicipalityService(Client);
            var      locationService     = new LocationService(Client, municipalityService);
            var      testCenterService   = new TestCenterService(Client);
            var      testService         = new TestService(Client);

            bool run = true;

            while (run)
            {
                Console.WriteLine("[A] Add new Citizen");
                Console.WriteLine("[B] Add new TestCenter and TestCenterManagement");
                Console.WriteLine("[C] Add new Test");
                Console.WriteLine("[D] Add Test to all Citizens");
                Console.WriteLine("[E] Add new Location");
                Console.WriteLine("[F] Add Locations to all Citizens");
                Console.WriteLine("[G] Seed data");
                Console.WriteLine("[H] View active cases for Municipalities");
                Console.WriteLine("[I] View active cases by Sex");
                Console.WriteLine("[J] View active cases by Age");
                Console.WriteLine("[K] View possible cases by Location three days prior");
                Console.WriteLine("[X] Quit");
                Console.WriteLine("INPUT: ");

                var userInput = Console.ReadKey();

                switch (userInput.KeyChar)
                {
                case 'A':
                {
                    Console.Write("Firstname: ");
                    string firstname = Console.ReadLine();
                    Console.Write("Lastname: ");
                    string lastname = Console.ReadLine();
                    Console.Write("SSN (XXXXXX-XXXX): ");
                    string ssn = Console.ReadLine();
                    Console.Write("Age: ");
                    string age = Console.ReadLine();
                    Console.Write("Sex: ");
                    string sex = Console.ReadLine();
                    Console.Write("Municipality: ");
                    string municipalityName = Console.ReadLine();

                    int municipalityId = municipalityService.GetId(municipalityName);

                    var newCitizen = new Citizen
                    {
                        Firstname       = firstname,
                        Lastname        = lastname,
                        SSN             = ssn,
                        Age             = int.Parse(age),
                        Sex             = sex,
                        Tests           = new List <Test>(),
                        Location_id     = new List <int>(),
                        Municipality_id = municipalityId
                    };

                    citizenService.AddCitizen(newCitizen);
                }
                break;

                case 'B':
                {
                    Console.Write("Municipality: ");
                    string municipalityName = Console.ReadLine();
                    Console.Write("Hours: ");
                    int hours = int.Parse(Console.ReadLine());
                    Console.Write("Phonenumber: ");
                    int phonenumber = int.Parse(Console.ReadLine());
                    Console.Write("Email: ");
                    string email = Console.ReadLine();

                    testCenterService.AddTestCenter(municipalityName, hours, phonenumber, email);
                }
                break;

                case 'C':
                {
                    Console.Write("Citizen-ID: ");
                    int citizenId = int.Parse(Console.ReadLine());
                    Console.Write("TestCenter-ID: ");
                    int testCenterId = int.Parse(Console.ReadLine());

                    if (Client.TestCenters.Find(t => t.TestCenterId == testCenterId).Any())
                    {
                        Console.WriteLine("No TestCenter with ID {0} exists.", testCenterId);
                        break;
                    }
                    else if (Client.Citizens.Find(c => c.CitizenId == citizenId).Any())
                    {
                        Console.WriteLine("No Citizen with ID {0} exists.", citizenId);
                        break;
                    }

                    testService.TestCitizen(citizenId, testCenterId);
                }
                break;

                case 'D':
                {
                    testService.TestAllCitizens();
                    Console.WriteLine("All citizens tested.");
                }
                break;

                case 'E':
                {
                    Console.Write("Citizen-ID: ");
                    int citizenId = int.Parse(Console.ReadLine());
                    Console.Write("Address: ");
                    string address = Console.ReadLine();
                    Console.Write("Zip: ");
                    int zip = int.Parse(Console.ReadLine());
                    Console.Write("Municipality name: ");
                    string municipalityName = Console.ReadLine();

                    locationService.AddLocation(citizenId, address, zip, municipalityName);
                }
                break;

                case 'F':
                {
                    locationService.AddLocationToAllCitizen();
                    Console.WriteLine("All Citizen have now locations");
                }
                break;

                case 'G':
                {
                    Console.WriteLine("Sure you want to seed? Seeding will reset all Citizens and Municipalities[Y/N]");
                    string userKey = Console.ReadLine();

                    if (userKey.Contains('Y'))
                    {
                        Seed();
                        Console.WriteLine("Seeding done!");
                    }
                    else
                    {
                        Console.WriteLine("Seeding canceled.");
                    }
                }
                break;

                case 'H':
                {
                    testCenterService.ActiveCovidCasesPerMunicipality();
                }
                break;

                case 'I':
                {
                    testCenterService.ActiveCovidCasesSex();
                }
                break;

                case 'J':
                {
                    Console.Write("Min age: ");
                    int minAge = int.Parse(Console.ReadLine());
                    Console.Write("Max age: ");
                    int maxAge = int.Parse(Console.ReadLine());
                    int cases  = testCenterService.ActiveCovidCasesAge(minAge, maxAge);
                    Console.WriteLine("Total number of cases: {0}", cases);
                }
                break;

                case 'K':
                {
                    Console.Write("Infected citizen's ID: ");
                    int            citizenId = int.Parse(Console.ReadLine());
                    List <Citizen> citizens  = citizenService.CitizensAtSameLocation(citizenId);
                    Console.WriteLine("Citizens which has been the at the same location as an infected: ");
                    foreach (var citizen in citizens)
                    {
                        Console.WriteLine("-------------------------------------------------------");
                        Console.WriteLine($"ID: {citizen.CitizenId}");
                        Console.WriteLine($"Name: {citizen.Firstname} {citizen.Lastname}");
                        Console.WriteLine($"SSN : {citizen.SSN}");
                        Console.WriteLine("-------------------------------------------------------");
                    }
                }
                break;

                case 'X':
                    run = false;
                    break;
                }

                Console.WriteLine("\nPress any key.");
                Console.ReadKey();
                Console.Clear();
            }
        }