//    var google_tag_params = {
        //    flight_originid : 'IST',
        //    flight_destid : 'JFK',
        //    flight_startdate : '2016-07-12',
        //    flight_enddate : '2016-07-19',
        //    flight_pagetype : 'availabilityInt'
        //};
        public AvailabilityFightListResponse ParseAvailabilityResults(AvailabilityFightListRequest request, OTA_AirAvailAndFaresRSType response)
        {
            //TODO : : OK::NOT:: bu iki bilgi requestin içine eklenebilir requet içinde code değilde airport eklenebilir bu sayede. bir ön mekenazima yapılıp onun istekleri yapmadan önce ilgili düzenlemeleri yapması istenebiir :)
            Airport departure = new Airport(request.origin, request.origin, "TR");
            Airport arrival = new Airport(request.destination, request.destination, "TR");

            AvailabilityFightListResponse formedResponse = new AvailabilityFightListResponse();

            if (response.Success && response.OriginDestinationOptionsExt.OriginDestinationOptionExt.Length > 0)
            {
                bool isDomestic = FlightHelper.FlightHelpers.IsFlightInTurkeyOrECN(departure, arrival);

                //string[] promoClasses = new string[0];
                if (isDomestic)
                {
                    //promoClasses = this.ProviderModel.GetDelimitedValues("DomesticPromoClasses", null, ';');
                }
                else
                {
                    //promoClasses = this.ProviderModel.GetDelimitedValues("InternationalPromoClasses", null, ';');
                }
                int nonInfants = request.adult + request.child + request.tsk + request.ogr; //FlightHelpers.GetNonInfantPassengerCounts(query);
                List<BookingClassAvailExtType> cheapestBookingClasses = new List<BookingClassAvailExtType>();
                OriginDestinationOptionExtType[] originDestinationOptionExt = response.OriginDestinationOptionsExt.OriginDestinationOptionExt;
                for (int i = 0; i < originDestinationOptionExt.Length; i++)
                {
                    OriginDestinationOptionExtType option = originDestinationOptionExt[i];
                    if (!request.directFlightsOnly || option.FlightSegmentExt.Length <= 1)
                    {
                        if (!option.FlightSegmentExt.Any((FlightSegmentExtType x) => x.BookingClassAvailExt == null))
                        {
                            FlightOption pgsOption = new FlightOption();
                            pgsOption.BookingProviderId = this.ProviderModel.ProviderNo;
                            pgsOption.BookingProviderCode = this.ProviderModel.ProviderCode;
                            pgsOption.RelatedQueryObject = query;
                            pgsOption.OptionFlag = "OW";
                            pgsOption.OriginDestinationFlag = string.Format("{0}-{1}", option.FlightSegmentExt.First<FlightSegmentExtType>().DepartureAirport.LocationCode, option.FlightSegmentExt.Last<FlightSegmentExtType>().ArrivalAirport.LocationCode);
                            pgsOption.TripType = E_TripTypes.OneWay;
                            pgsOption.FreeBaggageAllowance = new FreeBaggageAllowance[]
                            {
                                Common.GetBaggageAllowance(query, isDomestic)
                            };
                            pgsOption.Segments = new List<Segment>();
                            pgsOption.SegmentAvailabilities = new List<SegmentAvailability>();
                            int segmentIndex = 1;
                            FlightSegmentExtType[] flightSegmentExt = option.FlightSegmentExt;
                            for (int j = 0; j < flightSegmentExt.Length; j++)
                            {
                                FlightSegmentExtType segment = flightSegmentExt[j];
                                IEnumerable<BookingClassAvailExtType> availableBookingClasses =
                                    from x in segment.BookingClassAvailExt
                                    where x.ResBookDesigQuantity >= nonInfants
                                    select x;
                                SegmentAvailability pgsSegmentAvailability = new SegmentAvailability
                                {
                                    SegmentIndex = segmentIndex,
                                    BookingClasses = new List<BookingClassAvailability>()
                                };
                                foreach (BookingClassAvailExtType bookingClass in availableBookingClasses)
                                {
                                    pgsSegmentAvailability.BookingClasses.Add(new BookingClassAvailability
                                    {
                                        Code = bookingClass.ResBookDesigCode,
                                        AvailableSeats = bookingClass.ResBookDesigQuantity,
                                        IsPromo = promoClasses.Contains(bookingClass.ResBookDesigCode)
                                    });
                                }
                                pgsOption.SegmentAvailabilities.Add(pgsSegmentAvailability);
                                Segment pgsSegment = new Segment();
                                pgsSegment.Index = segmentIndex;
                                pgsSegment.OriginAirport = segment.DepartureAirport.LocationCode;
                                pgsSegment.DestinationAirport = segment.ArrivalAirport.LocationCode;
                                pgsSegment.OD_OriginAirport = option.FlightSegmentExt.First<FlightSegmentExtType>().DepartureAirport.LocationCode;
                                pgsSegment.OD_DestinationAirport = option.FlightSegmentExt.Last<FlightSegmentExtType>().ArrivalAirport.LocationCode;
                                pgsSegment.DepartureDateTime = DateTime.Parse(segment.DepartureDateTime);
                                pgsSegment.ArrivalDateTime = DateTime.Parse(segment.ArrivalDateTime);
                                pgsSegment.FlightNumber = segment.MarkettingAirline.CompanyShortName + segment.FlightNumber;
                                pgsSegment.MarketingAirline = segment.MarkettingAirline.CompanyShortName;
                                pgsSegment.OperatingAirline = pgsSegment.MarketingAirline;
                                pgsSegment.Equipment = segment.Equipment.AirEquipType;
                                BookingClassAvailExtType cheapestBookingClass = availableBookingClasses.FirstOrDefault((BookingClassAvailExtType x) => x.ResBookDesigCode == pgsSegmentAvailability.BookingClasses.Last<BookingClassAvailability>().Code);
                                cheapestBookingClasses.Add(cheapestBookingClass);
                                pgsSegment.BookingClassCode = cheapestBookingClass.ResBookDesigCode;
                                pgsSegment.FareBasisCode = pgsSegment.BookingClassCode;
                                pgsSegment.FareReference = cheapestBookingClass.FareDisplayInfos.FareDisplayInfo.Last<FareDisplayInfoType>().FareReference;
                                pgsSegment.FareReferenceId = cheapestBookingClass.FareDisplayInfos.FareDisplayInfo.Last<FareDisplayInfoType>().FareReferenceID;
                                pgsOption.Segments.Add(pgsSegment);
                                segmentIndex++;
                            }
                            result.FlightOptions.Add(pgsOption);
                        }
                    }
                }
                foreach (FlightOption pgsoption in result.FlightOptions)
                {
                    this.GetFareTypesInParallelThread(pgsoption);
                }
                this.CalculateFares(query, result, isDomestic, cheapestBookingClasses);
            }
            else
            {
                result.FlightOptions = null;
                result.HasError = true;
            }
            return result;
        }
        public List<OTA_AirAvailAndFaresRQType> CreateAvailabilityRequests(AvailabilityFightListRequest request)
        {
            //airport listesi elimizde olsaydı metadata gibi linq ile sorgu atabilirdik. veya db den soracağız. hava alanı listesini istek oluştururken static bir şekildede oluşturabiliriz.
            //query.IntendedSegments.First<AirQuery_Segment>().Destination;
            //buarada biz metadatadan arama yaparken sadece Airport Code üzerinden sorgu atıp diğer bilgileri oradan bulacağız ben şimdilik elle salladım.

            Airport departure = new Airport(request.origin, request.origin, "TR");
            Airport arrival = new Airport(request.destination, request.destination, "TR");

            string[] origins = new string[]
            {
                departure.Code
            };

            //IsCity deki amaç istanbuldan ankaraya uçacak ve istanbulda 2 ankarada 3 hava alanı var. kullanıcı ayrım yapmadan sorgulama yapmak istiyor. yani SAW (sabiha) veya burada amaç
            if (departure.IsCity && Common.CityAirports.ContainsKey(departure.Code))
            {
                origins = Common.CityAirports[departure.Code];
            }
            string[] destinations = new string[]
            {
                arrival.Code
            };
            if (arrival.IsCity && Common.CityAirports.ContainsKey(arrival.Code))
            {
                destinations = Common.CityAirports[arrival.Code];
            }

            return new List<OTA_AirAvailAndFaresRQType>
            {
                new OTA_AirAvailAndFaresRQType
                {
                    SequenceNmbr = 1,
                    SequenceNmbrSpecified = true,
                    PrimaryLangID = "1",
                    DirectFlightsOnly = request.directFlightsOnly,
                    DirectFlightsOnlySpecified = true,

                    POS = Common.GetPOSType(),
                    TravelerInfoSummary = new TravelerInfoSummaryType
                    {
                        AirTravelerAvail = new AirTravelerAvailType
                        {
                            PassengerTypeQuantity = this.GetPassengerQuantities(request),
                            temp = "temp"
                        }
                    },

                    OriginDestinationInformation = new OriginDestinationInformationType
                    {
                        OriginLocation = new LocationType
                        {
                            LocationCode = origins.First<string>()
                        },
                        DestinationLocation = new LocationType
                        {
                            LocationCode = destinations.First<string>()
                        },
                        DepartureDateTime =  request.date.ToString("yyyy-MM-dd")
                    }
                }
            };
        }
Пример #3
0
        //        public static string GetCountryCode(string phoneNumber)
        //        {
        //            return phoneNumber.Split(new char[]
        //            {
        //                '-'
        //            }).First<string>().Replace("+", "00");
        //        }
        //        public static string GetPhoneNumber(string phoneNumber)
        //        {
        //            return phoneNumber.Split(new char[]
        //            {
        //                '-'
        //            }).Last<string>();
        //        }
        //        public static string GetRawFlightNumber(string flightNumber)
        //        {
        //            int length = flightNumber.Length;
        //            return flightNumber.Substring(2, length - 2);
        //        }
        //        public static int[] GetPassengerCounts(AirQuery query)
        //        {
        //            AirQuery_PaxItem adultCount = query.Paxes.FirstOrDefault((AirQuery_PaxItem p) => p.PaxType == "ADT");
        //            AirQuery_PaxItem childCount = query.Paxes.FirstOrDefault((AirQuery_PaxItem p) => p.PaxType == "CHD");
        //            AirQuery_PaxItem infantCount = query.Paxes.FirstOrDefault((AirQuery_PaxItem p) => p.PaxType == "INF");
        //            AirQuery_PaxItem studentCount = query.Paxes.FirstOrDefault((AirQuery_PaxItem p) => p.PaxType == "STD");
        //            AirQuery_PaxItem seniorCount = query.Paxes.FirstOrDefault((AirQuery_PaxItem p) => p.PaxType == "SRC");
        //            AirQuery_PaxItem militaryCount = query.Paxes.FirstOrDefault((AirQuery_PaxItem p) => p.PaxType == "MIL");
        //            int adt = (adultCount != null) ? adultCount.Count : 0;
        //            int chd = (childCount != null) ? childCount.Count : 0;
        //            int inf = (infantCount != null) ? infantCount.Count : 0;
        //            int std = (studentCount != null) ? studentCount.Count : 0;
        //            int src = (seniorCount != null) ? seniorCount.Count : 0;
        //            int mil = (militaryCount != null) ? militaryCount.Count : 0;
        //            adt += std + src + mil;
        //            return new int[]
        //            {
        //                adt,
        //                chd,
        //                inf
        //            };
        //        }
        //        public static int GetNonInfantPassengerCounts(AirQuery query)
        //        {
        //            return (
        //                from x in query.Paxes
        //                where x.PaxType != "INF"
        //                select x).Sum((AirQuery_PaxItem y) => y.Count);
        //        }
        //        public static bool IsFlightInTurkey(AirQuery query)
        //        {
        //            bool isDomestic = false;
        //            AirQuery_Segment route = query.IntendedSegments[0];
        //            if (route.Origin.CountryCode == "TR" && route.Destination.CountryCode == "TR")
        //            {
        //                isDomestic = true;
        //            }
        //            return isDomestic;
        //        }
        public static bool IsFlightInTurkeyOrECN(Airport Origin, Airport Destination )
        {
            bool isDomestic = false;
            if ((Origin.CountryCode == "TR" || Origin.Code == "ECN") && (Destination.CountryCode == "TR" || Destination.Code == "ECN"))
            {
                isDomestic = true;
            }

            return isDomestic;
        }