Exemplo n.º 1
0
        public void TestCreate()
        {
            var today = DateTime.Now.Date;

            var itinerary = ItineraryType.Create(new ItinerarySnapshot
            {
                Id = 1,

                Outbound = new FlightSegmentSnapshot
                {
                    Airline = "British Airways",

                    FromAirportCode = "LHR",

                    ToAirportCode = "SEA",

                    DepartureTime = today,

                    ArrivalTime = today.AddDays(1),

                    DurationHours = 5,

                    TicketClass = TicketClass.Business
                },

                Return = new FlightSegmentSnapshot
                {
                    Airline = "Emirates",

                    FromAirportCode = "SEA",

                    ToAirportCode = "LHR",

                    DepartureTime = today.AddDays(7),

                    ArrivalTime = today.AddDays(8),

                    DurationHours = 6,

                    TicketClass = TicketClass.Economy
                },

                Price = 551.5M
            });

            Assert.Equal("British Airways", itinerary.Outbound.Airline);

            Assert.Equal("Emirates", itinerary.Return.Airline);

            Assert.Equal(11, itinerary.TotalDurationHours);

            Assert.Equal(551.5M, itinerary.Price);

            Assert.Equal("Multiple airlines", itinerary.AirlineName);
        }
Exemplo n.º 2
0
        private static VoyageType GetVoyageType(ItineraryType type)
        {
            switch (type)
            {
            case ItineraryType.OneWay:
                return(VoyageType.OneWay);

            case ItineraryType.Roundtrip:
                return(VoyageType.RoundTrip);

            case ItineraryType.Conjunction:
                return(VoyageType.TransitWay);

            case ItineraryType.Notch:
                return(VoyageType.Notch);

            default:
                throw new InvalidOperationException();
            }
        }
Exemplo n.º 3
0
        private static VoyageTypeValue GetVoyageTypeValue(ItineraryType itineraryType, int count)
        {
            switch (itineraryType)
            {
            case ItineraryType.OneWay:
                return(VoyageTypeValue.OneWay);

            case ItineraryType.Roundtrip:
                return(VoyageTypeValue.RoundTrip);

            case ItineraryType.Conjunction:
                return(count > 2 ? VoyageTypeValue.OneWayOrRound : VoyageTypeValue.TransitWay);

            case ItineraryType.Notch:
                return(VoyageTypeValue.Notch);

            default:
                throw new NotSupportedException("itineraryType");
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// 根据航程列表,得到行程类型;
        /// </summary>
        /// <param name="voyages">航程列表</param>
        /// <returns>行程类型</returns>
        /// <remarks>
        /// 给出的航程列表必须按照按照时间排列好。
        /// </remarks>
        public static ItineraryType GetItineraryType(List <AirportPair> voyages)
        {
            ItineraryType itineraryType = default(ItineraryType);

            if (voyages.Count == 1)
            {
                itineraryType = ItineraryType.OneWay;
            }
            else
            {
                if (voyages.Count == 2 && voyages[0].Departure == voyages[1].Arrival && voyages[1].Departure == voyages[0].Arrival)
                {
                    itineraryType = ItineraryType.Roundtrip;
                }
                else
                {
                    itineraryType = IsContinuousVoyages(voyages) ? ItineraryType.Conjunction : ItineraryType.Notch;
                }
            }

            return(itineraryType);
        }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="segments"></param>
        /// <param name="itineraryType"></param>
        /// <param name="passengerType"></param>
        /// <param name="isTeam"></param>
        /// <param name="patPrice">在双重类型的仓位上用户区分仓位类型,null的情况下只会选择普通类型</param>
        /// <returns></returns>
        public static IEnumerable <DataTransferObject.FlightQuery.FlightView> GetQueryFlightView(IEnumerable <Segment> segments,
                                                                                                 ItineraryType itineraryType, PassengerType passengerType, bool isTeam, PriceView patPrice)
        {
            var index              = 1;
            var result             = segments.Select(s => GetFlightView(s, passengerType)).OrderBy(item => item.Departure.Time).ToList();
            var voyageType         = GetVoyageTypeValue(itineraryType, result.Count);
            var passengerTypeValue = passengerType == PassengerType.Child ? PassengerTypeValue.Child : PassengerTypeValue.Adult;
            var travelTypeValue    = isTeam ? TravelTypeValue.Team : TravelTypeValue.Individual;

            result.ForEach(item => {
                item.Serial = index++;
                setBunkInfo(item, voyageType, passengerTypeValue, travelTypeValue, patPrice);
            });
            CheckFlights(result, itineraryType);
            return(result);
        }
Exemplo n.º 6
0
        public static IEnumerable <DataTransferObject.Order.FlightView> GetOrderFlightView(IEnumerable <Segment> segments,
                                                                                           ItineraryType itineraryType, PassengerType passengerType, bool isTeam)
        {
            var fv = GetQueryFlightView(segments, itineraryType, passengerType, isTeam, null);

            return(fv.Select(GetOrderFlightView));
        }
Exemplo n.º 7
0
 private static void CheckFlights(IEnumerable <DataTransferObject.FlightQuery.FlightView> flightViews, ItineraryType itineraryType)
 {
     if (flightViews.Count() > 1)
     {
         // 所有航段必须是同一航空公司
         var firstFlight = flightViews.First();
         if (flightViews.Any(f => f.AirlineCode != firstFlight.AirlineCode))
         {
             throw new CustomException("所有航段必须是同一乘运人乘运");
         }
         // 往返产品舱不能与其他舱位搭配
         var firstProdutionBunk = flightViews.FirstOrDefault(f => f.BunkType == BunkType.Production);
         if (firstProdutionBunk != null && !flightViews.All(f => f.BunkType == BunkType.Production && f.BunkCode == firstProdutionBunk.BunkCode))
         {
             throw new CustomException("往返产品舱只能与往返产品舱搭配销售");
         }
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// Becomes the round trip.
 /// </summary>
 public void BecomeRoundTrip()
 {
     _type = ItineraryType.RoundTrip;
 }
Exemplo n.º 9
0
 /// <summary>
 /// Becomes the single trip.
 /// </summary>
 public void BecomeSingleTrip()
 {
     _type = ItineraryType.SingleTrip;
 }