public async Task DeleteCandidate(int?id) { var address = await _context.Addresses.SingleOrDefaultAsync(a => a.CandidateId == id); if (address != null) { _context.Addresses.Remove(address); } var email = await _context.Emails.SingleOrDefaultAsync(e => e.CandidateId == id); if (email != null) { _context.Emails.Remove(email); } var phone = await _context.Phones.SingleOrDefaultAsync(p => p.CandidateId == id); if (phone != null) { _context.Phones.Remove(phone); } var candidatePosition = await _context.CandidatePositions.SingleOrDefaultAsync(c => c.CandidateId == id); if (candidatePosition != null) { _context.CandidatePositions.Remove(candidatePosition); } var candidate = await _context.Candidates.FindAsync(id); _context.Remove(candidate); await _context.SaveChangesAsync(); }