private void SetPatientDeleteTimer(int patientId) { PatientTimer timer = new PatientTimer { Interval = 157680000000, // 5 years in miliseconds AutoReset = false, patientId = patientId }; timer.Elapsed += DeletePatient; timer.Start(); }
private void DeletePatient(object source, ElapsedEventArgs e) { PatientTimer patientTimer = (PatientTimer)source; DbContextOptionsBuilder <ApplicationDbContext> op = new DbContextOptionsBuilder <ApplicationDbContext>(); op.UseSqlServer("Server=DESKTOP-CVC40GK;Database=PlacowkaMedyczna;Trusted_Connection=True;MultipleActiveResultSets=True"); var _db = new ApplicationDbContext(op.Options); Patient patientToDelete = _db.Patient.Where(p => p.Id == patientTimer.patientId).FirstOrDefault(); _db.Patient.Remove(patientToDelete); _db.SaveChanges(); patientTimer.Stop(); patientTimer.Dispose(); }