Example #1
0
        private void AddTestCenter()
        {
            //tilføj testcenter
            string[] hoursarr;
            int      open;
            int      close;

            do
            {
                Console.WriteLine("Enter Test center hours: \"open close\"");
                string hours = Console.ReadLine();
                hoursarr = hours.Split(" ");
            }while (hoursarr.Length != 2 || !int.TryParse(hoursarr[0], out open) || !int.TryParse(hoursarr[1], out close));

            Console.WriteLine("Enter Test center name: \"name\"");
            string name = Console.ReadLine();

            using (var unitOfWork = new UnitOfWork(new CovidContext()))
            {
                var testCenter = new TestCenter(open, close, name);

                unitOfWork.TestCenters.Add(testCenter);
                unitOfWork.Complete();
            }
        }
Example #2
0
        public async Task <IActionResult> CreateTestCenter(TestCenterDto testCenterDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            var newTestCenter = new TestCenter
            {
                City         = testCenterDto.City,
                SlotCapacity = testCenterDto.SlotCapacity,
                Street       = testCenterDto.Street,
                Name         = testCenterDto.Name,
                Postalcode   = testCenterDto.Postalcode
            };

            try
            {
                await _unitOfWork.TestCenters.AddAsync(newTestCenter);

                await _unitOfWork.SaveChangesAsync();

                return(CreatedAtAction(
                           nameof(Get),
                           new { id = newTestCenter.Id },
                           newTestCenter));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Example #3
0
        private void AddManagment()
        {
            //tilføj Testledelse
            Console.WriteLine("Skriv navn på testcenter der ledes:");
            var name = Console.ReadLine();

            Console.WriteLine("Indtast telefon nr. og email: \"tlf email\"");
            string[] res = Console.ReadLine().Split(" ");
            using (var unitOfWork = new UnitOfWork(new CovidContext()))
            {
                TestCenter           center = unitOfWork.TestCenters.GetAll().Where(s => s.CenterName == name).First();
                TestCenterManagement testCenterManagement = null;
                if (center != null)
                {
                    testCenterManagement = new TestCenterManagement(center.TestCenterId, res[0], int.Parse(res[1]));


                    unitOfWork.TestCenterManagements.Add(testCenterManagement);
                    unitOfWork.Complete();
                }
                else
                {
                    Console.WriteLine("Ugyldig Center navn.");
                    Console.WriteLine("Tryk på en knap for at vælge en ny mulighed");
                    Console.ReadKey();
                }
            }
        }
Example #4
0
        public async Task <IActionResult> PutTestCenter(int id, TestCenter testCenter)
        {
            if (id != testCenter.Id)
            {
                return(BadRequest());
            }

            _unitOfWork.TestCenters.UpdateTestCentersData(testCenter);

            try
            {
                await _unitOfWork.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!await TestCenterExistsAsync(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Example #5
0
        public async Task <ActionResult> DeleteTestCenter(int?id)
        {
            if (id == null)
            {
                return(BadRequest());
            }
            TestCenter testCenter = await _unitOfWork.TestCenterRepository.GetTestCenterByIdAsync(id.Value);

            if (testCenter == null)
            {
                return(NotFound());
            }

            _unitOfWork.TestCenterRepository.Delete(testCenter);

            try
            {
                await _unitOfWork.SaveChangesAsync();
            }
            catch (ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }

            return(NoContent());
        }
Example #6
0
        public async Task <ActionResult> PutTestCenter(int?id, TestCenterDto testCenterDto)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            TestCenter testCenter = await _unitOfWork.TestCenterRepository.GetTestCenterByIdAsync(id.Value);

            if (testCenter == null)
            {
                return(NotFound());
            }

            testCenter.Name         = testCenterDto.Name;
            testCenter.City         = testCenterDto.City;
            testCenter.Postcode     = testCenterDto.Postcode;
            testCenter.Street       = testCenterDto.Street;
            testCenter.SlotCapacity = testCenterDto.SlotCapacity;

            try
            {
                await _unitOfWork.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }

            return(NoContent());
        }
Example #7
0
        public async Task <TestCenter> RemoveTestCenterAsync(int testCenterId)
        {
            TestCenter cmp = await _dbContext.TestCenters
                             .Where(c => c.Id == testCenterId)
                             .FirstOrDefaultAsync();

            _dbContext.TestCenters.Remove(cmp);
            return(cmp);
        }
Example #8
0
 public TestCenterDto(TestCenter testCenter)
 {
     Id           = testCenter.Id;
     Name         = testCenter.Name;
     City         = testCenter.City;
     Postcode     = testCenter.Postcode;
     Street       = testCenter.Street;
     SlotCapacity = testCenter.SlotCapacity;
 }
Example #9
0
 public async Task AddTestCenterAsync(ZentrumDto testCenter)
 {
     TestCenter center = new TestCenter
     {
         Name         = testCenter.Name,
         City         = testCenter.City,
         Postalcode   = testCenter.Postalcode,
         Street       = testCenter.Street,
         SlotCapacity = testCenter.SlotCapacity
     };
     await _dbContext.TestCenters.AddAsync(center);
 }
Example #10
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TestCenter = await _unitOfWork.TestCenters.GetTestCenterByIdAsync(id.Value);

            if (TestCenter == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Example #11
0
        public async Task <ActionResult <ExaminationDto[]> > GetExaminationsByTestCenterId(int id)
        {
            TestCenter testCenter = await _unitOfWork.TestCenterRepository.GetTestCenterByIdAsync(id);

            if (testCenter == null)
            {
                return(NotFound());
            }

            ExaminationDto[] examinations = (await _unitOfWork.ExaminationRepository.GetExaminationByTestCenterIdAsync(testCenter.Id))
                                            .Select(e => new ExaminationDto(e))
                                            .ToArray();

            return(Ok(examinations));
        }
Example #12
0
        private void MainForm_Load(object sender, System.EventArgs e)
        {
            //Register log event handler
            TestCenter.Logger.LogEnterred +=
                new TestLogger.LogEventHandler(Logger_LogEnterred);

            //Grab the center
            m_testcenter = TestCenter.GetInstance();

            //Init the image list
            lstMessages.SmallImageList = new ImageList();
            lstMessages.SmallImageList.Images.Add(new Bitmap("error.bmp"));
            lstMessages.SmallImageList.Images.Add(new Bitmap("info.bmp"));
            lstMessages.SmallImageList.Images.Add(new Bitmap("warning.bmp"));

            UpdateStatus();
        }
Example #13
0
 private void cmdLogin_Click(object sender, System.EventArgs e)
 {
     if (txtUsername.Text == "" || txtPassword.Text == "")
     {
         FormError("Please enter a username and password");
     }
     else
     {
         if (!TestCenter.GetInstance().Authenticate(txtUsername.Text, txtPassword.Text))
         {
             FormError("Either the username or password is incorrect");
         }
         else
         {
             DialogResult = DialogResult.OK;
         }
     }
 }
Example #14
0
        public async Task <IActionResult> OnPostAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            TestCenter = await _unitOfWork.TestCenters.GetTestCenterByIdAsync(id.Value);

            if (TestCenter != null)
            {
                await _unitOfWork.TestCenters.RemoveTestCenterAsync(TestCenter.Id);

                await _unitOfWork.SaveChangesAsync();
            }

            return(RedirectToPage("./Index"));
        }
Example #15
0
        private void AddTestResult()
        {
            //tilføj testresultat
            Console.WriteLine("Indtast oplysninger om resultat: \"BorgerID centerID resultat(p/n) status");
            var        tokens = Console.ReadLine().Split(" ");
            int        borgerid;
            int        centerid;
            Citizen    cit  = null;
            TestCenter cent = null;

            if (int.TryParse(tokens[0], out borgerid) && int.TryParse(tokens[1], out centerid))
            {
                cit  = new UnitOfWork(new CovidContext()).Citizens.Find(c => c.ID == borgerid).First();
                cent = new UnitOfWork(new CovidContext()).TestCenters.Find(c => c.TestCenterId == centerid).First();

                if (cit.ID == borgerid && cent.TestCenterId == centerid)
                {
                    bool pos = false;
                    if (tokens[2] == "p")
                    {
                        pos = true;
                    }
                    using (var unitOfWork = new UnitOfWork(new CovidContext()))
                    {
                        TestDate test = new TestDate()
                        {
                            TestCenterID = centerid
                            ,
                            Citizen_ID = borgerid
                            ,
                            Date = DateTime.Now
                            ,
                            Status = tokens[3]
                            ,
                            Result = pos
                        };

                        unitOfWork.TestDates.Add(test);
                        unitOfWork.Complete();
                    }
                }
            }
        }
Example #16
0
        public void TestCenterCreation(TestCenterService tcs)
        {
            Console.WriteLine("Enter ID for the testcenter: ");
            int TestCenterId = int.Parse(Console.ReadLine());

            Console.WriteLine("Enter opening hours of the testcenter (fx. 8-16): ");
            string hours = Console.ReadLine();

            Console.WriteLine("Enter MunicipalityID for the municipality in which the testcenter is: ");
            int municipalityId = int.Parse(Console.ReadLine());

            var AddTestCenter = new TestCenter()
            {
                TestCenterId   = TestCenterId,
                OpenHours      = hours,
                MunicipalityId = municipalityId
            };

            tcs.Create(AddTestCenter);

            Console.WriteLine("TestCenter added!\n");
        }
Example #17
0
        private void AddTestResult()
        {
            //tilføj testresultat
            Console.WriteLine("Indtast oplysninger om resultat: \"BorgerID centerID resultat(p/n) status");
            var        tokens = Console.ReadLine().Split(" ");
            int        borgerid;
            int        centerid;
            Citizen    cit  = null;
            TestCenter cent = null;

            if (int.TryParse(tokens[0], out borgerid) && int.TryParse(tokens[1], out centerid))
            {
                cit = service.GetCitizens().Find(c => c.ID == borgerid);

                cent = service.GetTestCenters().Find(c => c.ID == centerid);


                if (cit.ID == borgerid && cent.ID == centerid)
                {
                    string pos = "neg";
                    if (tokens[2] == "p")
                    {
                        pos = "pos";
                    }

                    Test test = new Test()
                    {
                        TC     = cent.Name,
                        Res    = pos,
                        Date   = DateTime.Now,
                        Status = tokens[3]
                    };

                    service.AddTest(test, cit.ID);
                }
            }
        }
        public void AddTestCenter(string name, int hours, int phonenumber, string email)
        {
            var updatedMunicipality = client.Municipalities.FindOneAndDelete(m => m.Name == name);

            if (updatedMunicipality == null)
            {
                Console.WriteLine("No municipality with name '{0}' exists.", name);
                return;
            }

            var testcenter = new TestCenter
            {
                TestCenterId         = (int)client.TestCenters.CountDocuments(t => t.TestCenterId >= 0),
                Hours                = hours,
                TestCenterManagement = new Testcentermanagement {
                    Phonenumber = phonenumber, Email = email
                }
            };

            client.TestCenters.InsertOne(testcenter);

            updatedMunicipality.TestCenter_id.Add(testcenter.TestCenterId);
            client.Municipalities.InsertOne(updatedMunicipality);
        }
Example #19
0
        static void Main(string[] args)
        {
            //CLEAR DATABASE
            using (var context = new TrackerContext())
            {
                context.CitizenTestedAtTestCenters.RemoveRange(context.CitizenTestedAtTestCenters);
                context.CitizenWasAtLocations.RemoveRange(context.CitizenWasAtLocations);
                context.Citizens.RemoveRange(context.Citizens);
                context.TestCenters.RemoveRange(context.TestCenters);
                context.Locations.RemoveRange(context.Locations);
                context.TestCenterManagements.RemoveRange(context.TestCenterManagements);
                context.Municipalities.RemoveRange(context.Municipalities);
                context.SaveChanges();
            }


            //INSERT MUNICIPALITIES
            List <Municipality> municipalities = new List <Municipality>();

            string[] readLines = File.ReadAllLines(@"Municipality.csv");
            foreach (string line in readLines)
            {
                string[]     splitLine    = line.Split(',');
                Municipality municipality = new Municipality();
                municipality.Name       = splitLine[1];
                municipality.Population = int.Parse(splitLine[2]);
                municipalities.Add(municipality);
            }
            using (var context = new TrackerContext())
            {
                foreach (Municipality municipality in municipalities)
                {
                    context.Add(municipality);
                }
                context.SaveChanges();
            }

            //INSERT TEST CENTER MANAGEMENT
            List <TestCenterManagement> testCenterManagements = new List <TestCenterManagement>();

            readLines = File.ReadAllLines(@"TestCenterManagementData");
            foreach (string line in readLines)
            {
                string[]             splitLine  = line.Split(';');
                TestCenterManagement management = new TestCenterManagement();
                management.Name        = splitLine[0];
                management.PhoneNumber = int.Parse(splitLine[1]);
                management.Email       = splitLine[2];
                testCenterManagements.Add(management);
            }
            using (var context = new TrackerContext())
            {
                foreach (TestCenterManagement management in testCenterManagements)
                {
                    context.Add(management);
                }
                context.SaveChanges();
            }

            //INSERT LOCATIONS
            List <Location> locations = new List <Location>();

            readLines = File.ReadAllLines(@"LocationData");
            foreach (string line in readLines)
            {
                string[] splitLine = line.Split(';');
                Location location  = new Location();
                location.Address          = splitLine[0];
                location.MunicipalityName = splitLine[1];
                locations.Add(location);
            }
            using (var context = new TrackerContext())
            {
                foreach (Location location in locations)
                {
                    context.Add(location);
                }
                context.SaveChanges();
            }


            //INSERT TEST CENTERS
            List <TestCenter> testCenters = new List <TestCenter>();

            readLines = File.ReadAllLines(@"TestCenterData");
            foreach (string line in readLines)
            {
                string[]   splitLine  = line.Split(';');
                TestCenter testCenter = new TestCenter();
                testCenter.Name            = splitLine[0];
                testCenter.Hours           = splitLine[1];
                testCenter.ManagementName  = splitLine[2];
                testCenter.LocationAddress = splitLine[3];
                testCenters.Add(testCenter);
            }
            using (var context = new TrackerContext())
            {
                foreach (TestCenter testCenter in testCenters)
                {
                    context.Add(testCenter);
                }
                context.SaveChanges();
            }

            //INSERT CITIZENS
            List <Citizen> citizens = new List <Citizen>();

            readLines = File.ReadAllLines(@"CitizenData");
            foreach (string line in readLines)
            {
                string[] splitLine = line.Split(';');
                Citizen  citizen   = new Citizen();
                citizen.FirstName        = splitLine[0];
                citizen.LastName         = splitLine[1];
                citizen.Sex              = splitLine[2][0];
                citizen.Age              = int.Parse(splitLine[3]);
                citizen.SSN              = splitLine[4];
                citizen.MunicipalityName = splitLine[5];
                citizens.Add(citizen);
            }
            using (var context = new TrackerContext())
            {
                foreach (Citizen citizen in citizens)
                {
                    context.Add(citizen);
                }
                context.SaveChanges();
            }

            //INSERT CITIZENVISITS
            List <CitizenWasAtLocation> citizenWasAtLocations = new List <CitizenWasAtLocation>();

            readLines = File.ReadAllLines(@"LocationVisitedData");
            foreach (string line in readLines)
            {
                string[]             splitLine            = line.Split(';');
                CitizenWasAtLocation citizenWasAtLocation = new CitizenWasAtLocation();
                citizenWasAtLocation.VisitingCitizenSSN     = splitLine[0];
                citizenWasAtLocation.DateOfVisit            = DateTime.Parse(splitLine[1]);
                citizenWasAtLocation.VisitedLocationAddress = splitLine[2];
                citizenWasAtLocations.Add(citizenWasAtLocation);
            }
            using (var context = new TrackerContext())
            {
                foreach (CitizenWasAtLocation citizenWasAtLocation in citizenWasAtLocations)
                {
                    var Location = context.Locations
                                   .Include(b => b.Visits).First(b => b.Address == citizenWasAtLocation.VisitedLocationAddress);
                    Location.Visits.Add(citizenWasAtLocation);
                }
                context.SaveChanges();
            }

            //INSERT TESTS
            List <CitizenTestedAtTestCenter> citizenTestedAtTestCenters = new List <CitizenTestedAtTestCenter>();

            readLines = File.ReadAllLines(@"TestResultData");
            foreach (string line in readLines)
            {
                string[] splitLine = line.Split(';');
                CitizenTestedAtTestCenter citizenTestedAtTestCenter = new CitizenTestedAtTestCenter();
                citizenTestedAtTestCenter.CitizenSSN     = splitLine[0];
                citizenTestedAtTestCenter.Date           = DateTime.Parse(splitLine[1]);
                citizenTestedAtTestCenter.TestCenterName = splitLine[2];
                citizenTestedAtTestCenter.Result         = splitLine[3];
                citizenTestedAtTestCenter.Status         = splitLine[4];
                citizenTestedAtTestCenters.Add(citizenTestedAtTestCenter);
            }
            using (var context = new TrackerContext())
            {
                foreach (CitizenTestedAtTestCenter citizenTestedAtTestCenter in citizenTestedAtTestCenters)
                {
                    var Citizen = context.Citizens
                                  .Include(b => b.Tests).First(b => b.SSN == citizenTestedAtTestCenter.CitizenSSN);
                    Citizen.Tests.Add(citizenTestedAtTestCenter);
                }
                context.SaveChanges();
            }
        }
Example #20
0
 public List <TestCenterCitizen> GetTestCenter(TestCenter testcenter) => _testcentercitizen.Find(testcentercitizen => testcentercitizen.testCenter == testcenter).ToList();
Example #21
0
 public void UpdateTestCentersData(TestCenter oldTestCenter) =>
 _dbContext.TestCenters
 .Attach(oldTestCenter)
 .State = EntityState.Modified;
Example #22
0
 public void Update(int testCenterId, TestCenter testCenterIn) =>
 _testcenter.ReplaceOne(testcenter => testcenter.TestCenterId == testCenterId, testCenterIn);
Example #23
0
 public void Remove(TestCenter testCenterId) =>
 _testcenter.DeleteOne(testcenter => testcenter.TestCenterId == testCenterId.TestCenterId);
 public async Task AddAsync(TestCenter testCenters)
 {
     await _dbContext.TestCenter.AddAsync(testCenters);
 }
Example #25
0
 //CRUD operations
 public TestCenter Create(TestCenter testCenter)
 {
     _testcenter.InsertOne(testCenter);
     return(testCenter);
 }
        private async void TestCenterSaveCommandHandler()
        {
            bool verificationFailed = false;

            if (TestCenterUnderCreation.LocationAddress == string.Empty)
            {
                Window.TestCenterLocationRequired.Visibility = Visibility.Visible;
                verificationFailed = true;
            }
            else
            {
                Window.TestCenterLocationRequired.Visibility = Visibility.Hidden;
            }

            if (TestCenterUnderCreation.Name == string.Empty)
            {
                Window.TestCenterNameRequired.Visibility = Visibility.Visible;
                verificationFailed = true;
            }
            else
            {
                Window.TestCenterNameRequired.Visibility = Visibility.Hidden;
            }

            if (TestCenterUnderCreation.Hours == string.Empty)
            {
                Window.TestCenterHoursRequired.Visibility = Visibility.Visible;
                verificationFailed = true;
            }
            else
            {
                Window.TestCenterHoursRequired.Visibility = Visibility.Hidden;
            }

            if (TestCenterUnderCreation.ManagementName == string.Empty)
            {
                Window.TestCenterManagementRequired.Visibility = Visibility.Visible;
                verificationFailed = true;
            }
            else
            {
                Window.TestCenterManagementRequired.Visibility = Visibility.Hidden;
            }

            if (verificationFailed)
            {
                return;
            }
            else
            {
                try
                {
                    using (var context = new TrackerContext())
                    {
                        context.Add(TestCenterUnderCreation);
                        await context.SaveChangesAsync();

                        TestCenterUnderCreation = new TestCenter();
                        RaisePropertyChanged("TestCenters");
                    }
                }
                catch (Exception e)
                {
                    StringBuilder exceptionString = new StringBuilder();
                    while (e != null)
                    {
                        exceptionString.AppendLine(e.Message);
                        e = e.InnerException;
                    }
                    MessageBox.Show(exceptionString.ToString());
                }
            }
        }
 public void Delete(TestCenter testCenter)
 {
     _dbContext.TestCenter.Remove(testCenter);
 }
Example #28
0
 public void Remove(TestCenter testCenter)
 => _dbContext.TestCenters.Remove(testCenter);
Example #29
0
 public void Update(TestCenter tesCenter)
 => _dbContext.TestCenters.Update(tesCenter);
Example #30
0
 public async Task AddAsync(TestCenter testCenter)
 => await _dbContext
 .TestCenters
 .AddAsync(testCenter);