Пример #1
0
        public AirportItem GetLastAirportForProviderRoute(int ProviderId)
        {
            AirportItem result = null;

            try
            {
                var airportsTrips = _airportsTripRepo.FindAllBy(a => a.Providers.Where(p => p.Id == ProviderId).Any()).ToList();
                if (airportsTrips != null && airportsTrips.Count > 0)
                {
                    var airportTrip = airportsTrips.OrderBy(a => a.Id).OrderBy(t => t.Airport.Code).FirstOrDefault();
                    if (airportTrip != null)
                    {
                        result = new AirportItem(airportTrip.Airport.Code, airportTrip.Airport.Id, airportTrip.Airport.CityId, airportTrip.Airport.City.CountryId, airportTrip.Airport.City.Country.ContinentId, airportTrip.Airport.City.Code);
                    }
                }
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "ProviderId = " + ProviderId);
            }
            return(result);
        }
Пример #2
0
        public static List <AirportItem> getBADestinations(string Key)
        {
            List <AirportItem> Airports = new List <AirportItem>();

            try
            {
                var url            = "https://api.ba.com/rest-v1/v1/balocations";
                var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
                // httpWebRequest.ContentType = "application/json";
                httpWebRequest.Method = "GET";
                httpWebRequest.Headers.Add("client-key", Key);
                bool   result   = false;
                string CityCode = "";

                HttpWebResponse httpResponse = null;
                try
                {
                    httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
                    result       = true;
                }
                catch (WebException e)
                {
                    result = false;
                    string webError = FlightsEngine.Utils.Logger.GenerateWebError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
                }

                if (result)
                {
                    using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
                    {
                        var requestResult = streamReader.ReadToEnd();

                        if (!String.IsNullOrWhiteSpace(requestResult))
                        {
                            BARouteResponse ResultItem = JsonConvert.DeserializeObject <BARouteResponse>(requestResult);
                            if (ResultItem != null)
                            {
                                foreach (var Country in ResultItem.GetBA_LocationsResponse.Country)
                                {
                                    try
                                    {
                                        if (Country.City != null)
                                        {
                                            JavaScriptSerializer srRequestResult = new JavaScriptSerializer();
                                            dynamic jsonCities = srRequestResult.DeserializeObject(Country.City.ToString());
                                            if (jsonCities != null)
                                            {
                                                if (FlightsEngine.Utils.Utils.IsObjectsArray(jsonCities))
                                                {
                                                    foreach (var jsonCity in jsonCities)
                                                    {
                                                        CityCode = jsonCity["CityCode"];
                                                        if (FlightsEngine.Utils.Utils.IsPropertyExist(jsonCity, "Airport"))
                                                        {
                                                            dynamic jsonAirports = jsonCity["Airport"];
                                                            if (FlightsEngine.Utils.Utils.IsObjectsArray(jsonAirports))
                                                            {
                                                                foreach (var jsonAirport in jsonAirports)
                                                                {
                                                                    if (FlightsEngine.Utils.Utils.IsPropertyExist(jsonAirport, "AirportCode"))
                                                                    {
                                                                        AirportItem Airport = new AirportItem();
                                                                        Airport.Code     = Convert.ToString(jsonAirport["AirportCode"]);
                                                                        Airport.CityCode = CityCode;
                                                                        Airports.Add(Airport);
                                                                    }
                                                                }
                                                            }
                                                            else
                                                            {
                                                                if (FlightsEngine.Utils.Utils.IsPropertyExist(jsonAirports, "AirportCode"))
                                                                {
                                                                    AirportItem Airport = new AirportItem();
                                                                    Airport.Code     = Convert.ToString(jsonAirports["AirportCode"]);
                                                                    Airport.CityCode = CityCode;
                                                                    Airports.Add(Airport);
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                                else if (FlightsEngine.Utils.Utils.IsPropertyExist(jsonCities, "Airport"))
                                                {
                                                    CityCode = jsonCities["CityCode"];
                                                    dynamic jsonAirports = jsonCities["Airport"];
                                                    if (FlightsEngine.Utils.Utils.IsObjectsArray(jsonAirports))
                                                    {
                                                        foreach (var jsonAirport in jsonAirports)
                                                        {
                                                            if (FlightsEngine.Utils.Utils.IsPropertyExist(jsonAirport, "AirportCode"))
                                                            {
                                                                AirportItem Airport = new AirportItem();
                                                                Airport.Code     = Convert.ToString(jsonAirport["AirportCode"]);
                                                                Airport.CityCode = CityCode;
                                                                Airports.Add(Airport);
                                                            }
                                                        }
                                                    }
                                                    else
                                                    {
                                                        if (FlightsEngine.Utils.Utils.IsPropertyExist(jsonAirports, "AirportCode"))
                                                        {
                                                            AirportItem Airport = new AirportItem();
                                                            Airport.Code     = Convert.ToString(jsonAirports["AirportCode"]);
                                                            Airport.CityCode = CityCode;
                                                            Airports.Add(Airport);
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    catch (Exception ex)
                                    {
                                        FlightsEngine.Utils.Logger.GenerateError(ex, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, "Country = " + JsonConvert.SerializeObject(Country));
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                FlightsEngine.Utils.Logger.GenerateError(e, System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
            }

            return(Airports);
        }