Ejemplo n.º 1
0
        public async Task <dto.RetrieveBookingResponse> RetrieveBooking(dto.RetrieveBookingRequest retrieveBookingRequest)
        {
            if (string.IsNullOrEmpty(await _sessionBag.Signature()))
            {
                await _userSessionService.AnonymousLogonUnique();
            }
            var getBookingRequestData = new GetBookingRequestData
            {
                GetBookingBy       = GetBookingBy.RecordLocator,
                GetByRecordLocator = Mapper.Map <GetByRecordLocator>(retrieveBookingRequest)
            };
            var getBookingResponse = await _client.GetBookingAsync(new GetBookingRequest
            {
                ContractVersion        = _navApiContractVer,
                MessageContractVersion = _navMsgContractVer,
                Signature = await _sessionBag.Signature(),
                EnableExceptionStackTrace = false,
                GetBookingReqData         = getBookingRequestData
            });

            if (getBookingResponse.Booking == null)
            {
                await _sessionBag.SetBooking(null);

                throw new dto.ResponseErrorException(dto.Enumerations.ResponseErrorCode.BookingNotFound, new[] { "Booking not found. " });
            }
            var booking = Mapper.Map <dto.Booking>(getBookingResponse.Booking);
            await _sessionBag.SetBooking(booking);

            return(new dto.RetrieveBookingResponse {
                Booking = booking
            });
        }
Ejemplo n.º 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);
        }