public void ScheduleFlight(FlightModel flight) { _db.AddFlight(flight); ICollection<FlightModel> priorGateFlights = new FlightModel[0]; foreach (var gate in _db.Gates.OrderBy(g => g.Gate)) { var gateFlights = _db.GetFlightsForGate(gate.Gate).ToList(); try { if (priorGateFlights.Any(f => !flight.CanLoadAtGateNextTo(f))) { continue; } if (gateFlights.Any(f => !f.CanLoadAtSameGateAs(flight))) { continue; } _db.SetFlightGate(flight, gate.Gate); break; } finally { priorGateFlights = gateFlights; } } }
private GateModel FindOpenGateFor(FlightModel flight) { ICollection<FlightModel> priorGateFlights = new FlightModel[0]; foreach (var gate in Gates.OrderBy(g => g.Gate)) { var gateFlights = GetFlightsForGate(gate.Gate).ToList(); try { if (priorGateFlights.Any(f => !flight.CanLoadAtGateNextTo(f))) { continue; } if (gateFlights.Any(f => !f.CanLoadAtSameGateAs(flight))) { continue; } return gate; } finally { priorGateFlights = gateFlights; } } return null; }