using System; using System.Collections.Generic; using System.Linq; using System.Web; using AirlineServer.Models; namespace AirlineServer.Helper { public static class FindFlight { public static ICollection> Search( ICollection flights, DateTime startTime, DateTime endTime, string destination, string origin, int numberOfSeats) { ICollection> free_flights = new List>(); var flightsWithSeats = FindFlight .FlightsWithSeats(flights, numberOfSeats); var flightsTo= FindFlight .FlightsTo(flightsWithSeats, destination, origin, startTime); var flightsBack = FindFlight .FlightsBack(flightsWithSeats, destination, origin, endTime); free_flights.Add(flightsTo); free_flights.Add(flightsBack); return free_flights; } public static IEnumerable FlightsWithSeats( ICollection raw_flights, int numberOfSeats) { IEnumerable flights = new List(); flights = raw_flights.Where(f => (f.MaxSeats - f.BookedSeats) > numberOfSeats); return flights; } public static IEnumerable FlightsTo(IEnumerable raw_flights, string destination, string origin, DateTime startTime) { IEnumerable flights = new List(); flights = raw_flights.Where(f => f.Destination.City.Name == destination & f.Origin.City.Name == origin & f.StartTime == startTime); return flights; } // Since this function searches for a flight back the arguments // destination and origin get used in reverse. public static IEnumerable FlightsBack(IEnumerable raw_flights, string destination, string origin, DateTime endTime) { IEnumerable flights = new List(); flights = raw_flights.Where(f => f.Destination.City.Name == origin & f.Origin.City.Name == destination & f.StartTime == endTime); return flights; } } }