private void BuildWaysFromNode(string dispatchCity, DepartureDays departureDay, TimeSpan departureTime) { var currentNode = Nodes.Find(node => node.Name == dispatchCity); currentNode.IsChecked = true; var flightsFromNode = Flights.FindAll(route => route.DispatchCity == dispatchCity); foreach (var route in flightsFromNode) { var bestFlight = route.FindBestFlight(departureDay, departureTime); var arrivalNode = Nodes.Find(node => node.Name == route.ArrivalCity); if (arrivalNode.TimeOfRoute > currentNode.TimeOfRoute + bestFlight.FlightTime) { /*Костыль с поиском дня следующего вылета*/ var timeUntilFlight = bestFlight.FlightTime - bestFlight.Flight.TakeTimeInAir(); var timeOfDeparture = departureTime + timeUntilFlight; var nextDepartureDay = departureDay; for (var i = 0; i < timeOfDeparture.Days; i++) { nextDepartureDay = nextDepartureDay.Next(); } /*--------------------------------------------*/ arrivalNode.TimeOfRoute = currentNode.TimeOfRoute + bestFlight.FlightTime; arrivalNode.RouteToTheNode = new List <GraphFlight>(currentNode.RouteToTheNode); arrivalNode.RouteToTheNode.Add(new GraphFlight(bestFlight.Flight, route, nextDepartureDay, bestFlight.FlightTime)); } Flights.RemoveAll(flights => flights.DispatchCity == currentNode.Name && flights.ArrivalCity == route.ArrivalCity); Flights.RemoveAll(flights => flights.DispatchCity == route.ArrivalCity && flights.ArrivalCity == currentNode.Name); } var nextNode = TakeNodeWithMinTimeOfRoute(); if (nextNode != null) { var previousNode = nextNode.RouteToTheNode[nextNode.RouteToTheNode.Count - 1]; var departureDate = previousNode.TakeArrivalDate((DepartureDays)previousNode.DepartureDay); BuildWaysFromNode(nextNode.Name, departureDate.arrivalDay, departureDate.arrivalTime); } }