Example #1
0
        public async Task <IActionResult> GetFlights([FromQuery] string relative_to)
        {
            string    request = Request.QueryString.Value;
            ArrayList flights = new ArrayList();
            DateTime  time;

            try
            {
                // convert relative_to string to DateTime object
                time = DateTime.ParseExact(relative_to, "yyyy-MM-ddTHH:mm:ssZ",
                                           System.Globalization.CultureInfo.InvariantCulture).ToUniversalTime();
                // getting the inner server flights
                flights = myFlightsManager.GetFlightsByTime(time);
            }
            catch
            {
                return(BadRequest("Failed receiving flights"));
            }
            // if also need to check the servers
            if (request.Contains("sync_all"))
            {
                // getting all servers flights
                Tuple <bool, ArrayList> result = await Task.Run(
                    () => serversManager.GetExternalFlights(time));

                bool      failed          = result.Item1;
                ArrayList externalFlights = result.Item2;
                // if the request to the servers failed
                if (failed)
                {
                    return(BadRequest("Failed receiving flights from servers"));
                }
                flights.AddRange(externalFlights);
            }
            return(Ok(flights));
        }