public async Task <ActionResult <ConferenceDTO.SpeakerResponse> > DeleteSpeaker(int id) { var speaker = await _speakersRepository.DeleteAsync(id); if (speaker == null) { return(NotFound()); } foreach (var sessionId in speaker.SessionSpeakers.Select(ss => ss.SessionId)) { var session = await _sessionsRepository.GetByIdAsync(sessionId); if (!session.SessionSpeakers.Any()) { await _sessionsRepository.DeleteAsync(sessionId); } } return(speaker.MapSpeakerResponse()); }