예제 #1
0
 public static List <PopularFlightsAirportDto> GetPopularFlights()
 {
     using (DBEntities dbConn = new DBEntities())
     {
         return(FlightProxy.GetPopularFlightsAirportList(dbConn));
     }
 }
예제 #2
0
        public static FlightSearchResponseDto SearchFlights(string origin, string destination)
        {
            //container for search results
            FlightSearchResponseDto response = new FlightSearchResponseDto();

            try
            {
                //handle same airoprt search - client may not be checking
                if (origin.Equals(destination, StringComparison.OrdinalIgnoreCase))
                {
                    response.Flights     = new List <FlightDto>();
                    response.Airports    = new List <AirportDto>();
                    response.Airlines    = new List <AirlineDto>();
                    response.UserMessage = "Origin and destination are the same airport.";

                    return(response);
                }

                using (DBEntities dbConn = new DBEntities())
                {
                    //get flights with matching origin and destination
                    var matchingFlights = FlightProxy.FindFlights(dbConn, origin, destination);

                    //no matching flights
                    if (matchingFlights.Count == 0)
                    {
                        response.Flights     = new List <FlightDto>();
                        response.Airports    = new List <AirportDto>();
                        response.Airlines    = new List <AirlineDto>();
                        response.UserMessage = "No available flights";

                        return(response);
                    }

                    //return data
                    response.Flights     = GetShortestFlightsByDistance(matchingFlights);
                    response.UserMessage = string.Format("{0} flights.", response.Flights.Count);

                    var iataCodes     = response.Flights.SelectMany(q => q.Routes.Select(r => r.Destination)).Union(response.Flights.SelectMany(q => q.Routes.Select(r => r.Origin)));
                    var airlinesCodes = response.Flights.SelectMany(q => q.Routes.Select(r => r.Airline));

                    response.Airports = FlightProxy.GetAirports(dbConn, iataCodes);
                    response.Airlines = FlightProxy.GetAirlines(dbConn, airlinesCodes);
                }

                return(response);
            }
            catch (Exception ex)
            {
                //log ex
                throw new Exception("Unexpected Error");
            }
        }
예제 #3
0
        public static List <AirportDto> SearchAirports(string letters)
        {
            string searchLetters = HttpUtility.UrlDecode(letters);

            searchLetters = searchLetters.Replace(" ", ",").Replace(",,", ",").Replace(",", "*,") + "*";

            //check for string and length of string in case client isn't
            if (string.IsNullOrWhiteSpace(letters) || letters.Length < 3)
            {
                return(new List <AirportDto>());
            }

            using (DBEntities dbConn = new DBEntities())
            {
                return(FlightProxy.SearchAirports(dbConn, searchLetters));
            }
        }
예제 #4
0
        public async Task <IActionResult> EditFlightsPut(FlightProxy flight)
        {
            var client = GetClient();
            HttpResponseMessage response = await client.PutAsJsonAsync($@"api/airport/{flight.FlightId}", flight);

            if (response.IsSuccessStatusCode)
            {
                string content = await response.Content.ReadAsStringAsync();

                var model = await response.Content.ReadAsAsync <FlightProxy>();

                return(RedirectToAction("Index"));
                //return View(model);
            }
            else
            {
                return(NotFound());
            }
        }
예제 #5
0
        public void StartFlight(bool access)
        {
            var proxy = new FlightProxy(access);

            proxy.StartFlight(_spaceship);
        }