public IActionResult DeleteDoctor(DeleteDoctorRequest deleteDoctorRequest) { var prescriptionList = _context.Prescription.Where(e => e.IdDoctor == deleteDoctorRequest.IdDoctor).ToList(); ArrayList prescription_MedicamantList = new ArrayList(); foreach (Prescription prescription in prescriptionList) { prescription_MedicamantList.Add(_context.GetPrescription_Medicamant.Where(e => e.IdPrescription == prescription.IdPrescription)); } foreach (GetPrescription_Medicamant prescription_Medicamant in prescription_MedicamantList) { _context.Remove(prescription_Medicamant); } foreach (Prescription prescription in prescriptionList) { _context.Remove(prescription); } _context.Remove(_context.Doctor.Where(e => e.IdDoctor == deleteDoctorRequest.IdDoctor).ToList().First()); _context.SaveChanges(); return(Ok("Usunieto doktora wraz ze wszystkimi receptami wystawionymi przez tego doktora")); }