public async Task <IActionResult> Delete(int id) { Instructor deleteInstructor = _instructorsRepository .GetSingle(i => i.ID == id, i => i.CourseAssignments); var departments = _departmentsRepository .FindBy(d => d.InstructorID == id) .ToList(); departments.ForEach(d => d.InstructorID = null); // Delete instructor(s) in Departments if (deleteInstructor == null) { return(new NotFoundResult()); } else { _instructorsRepository.Delete(deleteInstructor); await _instructorsRepository.CommitAsync(); return(new NoContentResult()); } }