internal void UpdatePatientStatus() { while (run) { Thread.Sleep(500); int recoveredPatientsCount = 0, deadPatientsCount = 0; using (var context = new KrankenhausSjukhusetDbContext()) { int numberOfIllPatients = context.Patients.Where(p => p.IllnessLevel > 0 && p.IllnessLevel < 10).Count(); //antalet sjuka personer //kollar hur många patienter som ligger inne eller befinner sig i kön if (numberOfIllPatients == 0) { run = false; return; //tråden och programmet avlutas, corona is no more } var allPatients = (from p in context.Patients where p.StatusID == 1 || p.StatusID == 2 || p.StatusID == 3 select p).ToList(); foreach (var p in allPatients) { if (p.IllnessLevel <= 0) { p.StatusID = 4; //tillfrisknad :) recoveredPatientsCount++; } else if (p.IllnessLevel >= 10) { p.StatusID = 5; //rip deadPatientsCount++; } } context.SaveChanges(); } var stats = new RecoveredAndDeathsStatisiticsEventArgs(recoveredPatientsCount, deadPatientsCount); RecoveredAndDeathsEventSender(stats); } }
internal virtual void RecoveredAndDeathsEventSender(RecoveredAndDeathsStatisiticsEventArgs args) { RecoveredAndDeathEvent?.Invoke(this, args); }