Beispiel #1
0
        public async Task <dto.SellResponse> ChangeFlights(dto.ChangeFlightsRequest changeFlightsRequest)
        {
            var signature = await _sessionBag.Signature();

            var booking = await _sessionBag.Booking();

            var sellFlightsResponse = new dto.SellResponse();

            for (var i = changeFlightsRequest.JourneySellKeys.Length - 1; i >= 0; i--)
            {
                if (changeFlightsRequest.JourneySellKeys[i] == null ||
                    string.IsNullOrEmpty(changeFlightsRequest.JourneySellKeys[i].JourneySellKey) ||
                    string.IsNullOrEmpty(changeFlightsRequest.JourneySellKeys[i].FareSellKey))
                {
                    continue;
                }
                var cancelResponse = await CancelFlight(i);

                if (cancelResponse.Error != null)
                {
                    //throw new dto.ResponseErrorException(
                    //    dto.Enumerations.ResponseErrorCode.ChangeFlightFailure, cancelResponse.Error.ErrorText);
                    return(new dto.SellResponse {
                        BookingUpdateResponseData = cancelResponse
                    });
                }
            }
            for (var i = 0; i < changeFlightsRequest.JourneySellKeys.Length; i++)
            {
                if (changeFlightsRequest.JourneySellKeys[i] == null ||
                    string.IsNullOrEmpty(changeFlightsRequest.JourneySellKeys[i].JourneySellKey) ||
                    string.IsNullOrEmpty(changeFlightsRequest.JourneySellKeys[i].FareSellKey))
                {
                    continue;
                }
                var sellRequest = new dto.SellJourneyByKeyRequestData
                {
                    JourneySellKeys = new[] { changeFlightsRequest.JourneySellKeys[i] },
                    CurrencyCode    = booking.CurrencyCode,
                    PaxTypeCounts   = GetPaxTypeCounts(booking)
                };
                sellFlightsResponse = await SellFlights(sellRequest);

                if (sellFlightsResponse.BookingUpdateResponseData.Error != null)
                {
                    //throw new dto.ResponseErrorException(
                    //    dto.Enumerations.ResponseErrorCode.ChangeFlightFailure, sellFlightsResponse.BookingUpdateResponseData.Error.ErrorText);
                    return(sellFlightsResponse);
                }
                var resellSSRsResponse = await _ssrsService.ResellSSRs(i, changeFlightsRequest.ResellSeatSSRs, changeFlightsRequest.WaiveSeatFee);

                if (resellSSRsResponse.Error != null)
                {
                    //throw new dto.ResponseErrorException(
                    //    dto.Enumerations.ResponseErrorCode.ChangeFlightFailure, resellSSRsResponse.Error.ErrorText);
                    return(new dto.SellResponse {
                        BookingUpdateResponseData = resellSSRsResponse
                    });
                }
            }
            return(sellFlightsResponse);
        }
Beispiel #2
0
        public async Task <dto.SellResponse> SellFlights(dto.SellJourneyByKeyRequestData sellJourneyByKeyRequestData)
        {
            if (string.IsNullOrEmpty(await _sessionBag.Signature()))
            {
                await _userSessionService.AnonymousLogonUnique();
            }
            var signature = await _sessionBag.Signature();

            if (await _sessionBag.Booking() != null)
            {
                // cancel previously selected flights (if any) for New Bookings only
                var booking = await _bookingService.GetSessionBooking();

                if (string.IsNullOrEmpty(booking.RecordLocator) && booking.Journeys != null && booking.Journeys.Length > 0 && booking.Passengers != null && booking.Passengers.Length > 0)
                {
                    // totally clear booking if pax type counts are different
                    if (!PaxCountsAreTheSame(booking, sellJourneyByKeyRequestData))
                    {
                        await _bookingService.ClearStateBooking();
                    }
                    // pax type counts are the same so just cancel the journeys
                    else
                    {
                        var cancelData = new CancelRequestData
                        {
                            CancelBy      = CancelBy.Journey,
                            CancelJourney = new CancelJourney
                            {
                                CancelJourneyRequest = new CancelJourneyRequest
                                {
                                    Journeys = Mapper.Map <Journey[]>(booking.Journeys.ToArray())
                                }
                            }
                        };
                        try
                        {
                            await _client.CancelAsync(new CancelRequest
                            {
                                ContractVersion        = _navApiContractVer,
                                MessageContractVersion = _navMsgContractVer,
                                Signature = signature,
                                EnableExceptionStackTrace = false,
                                CancelRequestData         = cancelData
                            });
                        }
                        catch {
                            await _bookingService.ClearStateBooking();
                        }
                    }
                }
            }
            var flightsSellRequestData = new SellRequestData
            {
                SellBy = SellBy.JourneyBySellKey,
                SellJourneyByKeyRequest = new SellJourneyByKeyRequest
                {
                    SellJourneyByKeyRequestData = Mapper.Map <SellJourneyByKeyRequestData>(sellJourneyByKeyRequestData),
                }
            };
            var stopWatch           = _perfLogSettings.EnableNavApiLogging ? Stopwatch.StartNew() : null;
            var sellFlightsResponse = await _client.SellAsync(new SellRequest
            {
                ContractVersion        = _navApiContractVer,
                MessageContractVersion = _navMsgContractVer,
                Signature = signature,
                EnableExceptionStackTrace = false,
                SellRequestData           = flightsSellRequestData
            });

            //_navApiContractVer, false, _navMsgContractVer,
            //signature, flightsSellRequestData);
            if (_perfLogSettings.EnableNavApiLogging && stopWatch != null)
            {
                stopWatch.Stop();
                var msecs = stopWatch.ElapsedMilliseconds;
                _logger.WriteTimedLog(msecs, "BookingManager.SellAsync" + "|" + signature);
            }
            var returnResponse = new dto.SellResponse();
            // Sell infant SSR
            var infantPaxCount = Array.Find(sellJourneyByKeyRequestData.PaxTypeCounts, p => p.PaxTypeCode == Global.INFANT_CODE);

            if (infantPaxCount != null && infantPaxCount.PaxCount > 0)
            {
                var infantSegmentSSRRequests = await CreateSegmentSSRRequests(sellJourneyByKeyRequestData);

                var infantSSRSellRequestData = new SellRequestData
                {
                    SellBy  = SellBy.SSR,
                    SellSSR = new SellSSR
                    {
                        SSRRequest = new SSRRequest
                        {
                            CurrencyCode       = sellJourneyByKeyRequestData.CurrencyCode,
                            SegmentSSRRequests = infantSegmentSSRRequests
                        }
                    }
                };
                var stopWatch2       = _perfLogSettings.EnableNavApiLogging ? Stopwatch.StartNew() : null;
                var sellSSRsResponse = await _client.SellAsync(new SellRequest
                {
                    ContractVersion        = _navApiContractVer,
                    MessageContractVersion = _navMsgContractVer,
                    Signature = signature,
                    EnableExceptionStackTrace = false,
                    SellRequestData           = infantSSRSellRequestData
                });

                //_navApiContractVer, false, _navMsgContractVer,
                //signature, infantSSRSellRequestData);
                if (_perfLogSettings.EnableNavApiLogging && stopWatch != null)
                {
                    stopWatch2.Stop();
                    var msecs = stopWatch2.ElapsedMilliseconds;
                    _logger.WriteTimedLog(msecs, "BookingManager.SellAsync(INF)" + "|" + signature);
                }
                returnResponse = Mapper.Map <dto.SellResponse>(sellSSRsResponse);
            }
            else
            {
                returnResponse = Mapper.Map <dto.SellResponse>(sellFlightsResponse);
            }
            var stateBooking = await _bookingService.GetSessionBooking(true);

            await _sessionBag.SetBooking(stateBooking);

            if (string.IsNullOrEmpty(stateBooking.RecordLocator))
            {
                var paxesWithInfant = new List <dto.Passenger>();
                foreach (var pax in (await _sessionBag.Booking()).Passengers.ToList().FindAll(p => p.PassengerFees.ToList().Find(
                                                                                                  f => f.FeeCode == Global.INFANT_CODE) != null))
                {
                    if (pax.Infant == null)
                    {
                        pax.Infant = new dto.PassengerInfant();
                        paxesWithInfant.Add(pax);
                    }
                }
                if (paxesWithInfant.Count() > 0)
                {
                    var updatePaxesWithInfantsResult = await _passengerService.UpdatePassengers(
                        new dto.UpdatePassengersRequestData {
                        Passengers = paxesWithInfant.ToArray()
                    });

                    if (updatePaxesWithInfantsResult.Error != null)
                    {
                        throw new Exception(updatePaxesWithInfantsResult.Error.ErrorText);
                    }
                    await _sessionBag.SetBooking(await _bookingService.GetSessionBooking(true));
                }
            }
            return(returnResponse);
        }