private void validateSupervisorReferenceCycle( long id, long?supervisorId, IList <Employee> supervisors//Chain ) { if (supervisorId == null) { return; } var supervisor = employeeRepository.FindByIds(new List <long> { supervisorId ?? 0 }).FirstOrDefault(); if (supervisor == null) { throw BusinessException.IllegalSupervisorId(supervisorId ?? 0); } supervisors.Add(supervisor); if (id == supervisorId) { IList <Employee> cycle = new List <Employee>(supervisors); cycle.Insert(0, supervisors[supervisors.Count - 1]); throw BusinessException.SupervisorCycle(id, cycle); } validateSupervisorReferenceCycle(id, supervisor.SupervisorId, supervisors); }