public async Task <ActionResult <IEnumerable <Flight> > > GetFligths()
        {
            var flightItems = await _flightRepository.GetFlights();

            if (flightItems != null)
            {
                return(Ok(_mapper.Map <IEnumerable <FlightDTO> >(flightItems)));
            }
            return(NotFound());
        }
Exemplo n.º 2
0
        public IHttpActionResult CheckAvailability(string from,
                                                   string to, int pax)
        {
            var flights = _flightsRepository.GetFlights();

            if (flights == null)
            {
                var resp = new HttpResponseMessage(HttpStatusCode.NotFound)
                {
                    Content      = new StringContent("No flights found"),
                    ReasonPhrase = "No flights found"
                };
                throw new HttpResponseException(resp);
            }
            flights = flights.Where(f => f.StartTime > Convert.ToDateTime(from));

            flights = flights.Where(f => f.EndTime <= Convert.ToDateTime(to));

            flights = flights.Where(x => x.PassengerCapacity >= pax);
            return(Ok(flights));
        }