private async Task <SegmentSSRRequest[]> CreateSegmentSSRRequests(dto.SellJourneyByKeyRequestData sellJourneyByKeyRequestData) { var segmentSSRRequests = new List <SegmentSSRRequest>(); var infantPaxCount = Array.Find(sellJourneyByKeyRequestData.PaxTypeCounts, p => p.PaxTypeCode.Equals(Global.INFANT_CODE)); if (infantPaxCount != null && infantPaxCount.PaxCount > 0) { var ssrs = await _resourcesService.GetSSRList(await _sessionBag.CultureCode()); var infantSsr = Array.Find(ssrs.SSRList, p => p.SSRCode == Global.INFANT_CODE); var sellKeyList = Mapper.Map <SellKeyList[]>(sellJourneyByKeyRequestData.JourneySellKeys); var journeys = NewskiesHelper.GetJourneysFromSellKeys(sellKeyList).ToList(); var paxNumbers = new List <int>(); for (var i = 0; i < infantPaxCount.PaxCount; i++) { paxNumbers.Add(i); } var journeySegmentLegIndexes = new List <Tuple <int, List <Tuple <int, int[]> > > >(); for (var j = 0; j < journeys.Count(); j++) { var segmentLegIndexes = new List <Tuple <int, int[]> >(); for (var s = 0; s < journeys[j].Segments.Length; s++) { segmentLegIndexes.Add(new Tuple <int, int[]>(s, null)); } journeySegmentLegIndexes.Add(new Tuple <int, List <Tuple <int, int[]> > >(j, segmentLegIndexes)); } segmentSSRRequests = NewskiesHelper.CreateSegmentSSRRequests( journeys, Mapper.Map <SSR>(infantSsr), paxNumbers.ToArray(), 1, journeySegmentLegIndexes); } return(segmentSSRRequests.ToArray()); }
private bool PaxCountsAreTheSame(dto.Booking booking, dto.SellJourneyByKeyRequestData sellJourneyByKeyRequestData) { var adtCount = sellJourneyByKeyRequestData.PaxTypeCounts.ToList().Find(p => p.PaxTypeCode == Global.ADULT_CODE)?.PaxCount; var chdCount = sellJourneyByKeyRequestData.PaxTypeCounts.ToList().Find(p => p.PaxTypeCode == Global.CHILD_CODE)?.PaxCount; var infCount = sellJourneyByKeyRequestData.PaxTypeCounts.ToList().Find(p => p.PaxTypeCode == Global.INFANT_CODE)?.PaxCount; var bookingAdtCount = booking.Passengers.ToList().FindAll(p => p.PassengerTypeInfo.PaxType == "ADT").Count(); var bookingChdCount = booking.Passengers.ToList().FindAll(p => p.PassengerTypeInfo.PaxType == "CHD").Count(); var bookingInfCount = booking.Passengers.ToList().FindAll(p => p.Infant != null).Count(); return((adtCount.HasValue ? adtCount.Value : 0) == bookingAdtCount && (chdCount.HasValue ? chdCount.Value : 0) == bookingChdCount && (infCount.HasValue ? infCount.Value : 0) == bookingInfCount); }
private void CleanSellJourneyByKeyRequestData(dto.SellJourneyByKeyRequestData data) { var cleanedData = new List <dto.SellKeyList>(); foreach (var sellKey in data.JourneySellKeys) { if (!string.IsNullOrEmpty(sellKey.JourneySellKey) && !string.IsNullOrEmpty(sellKey.FareSellKey)) { cleanedData.Add(new dto.SellKeyList { JourneySellKey = sellKey.JourneySellKey, FareSellKey = sellKey.FareSellKey }); } } data.JourneySellKeys = cleanedData.ToArray(); }
public async Task <dto.PriceItinararyResponse> GetPriceItinerary(dto.SellJourneyByKeyRequestData sellJourneyByKeyRequestData) { var signature = !string.IsNullOrEmpty(await _sessionBag.Signature()) ? await _sessionBag.Signature() : await _userSessionService.GetAnonymousSharedSignature(); CleanSellJourneyByKeyRequestData(sellJourneyByKeyRequestData); var infantSegmentSSRRequests = await CreateSegmentSSRRequests(sellJourneyByKeyRequestData); var priceItineraryRequest = new ItineraryPriceRequest { SSRRequest = new SSRRequest { SegmentSSRRequests = infantSegmentSSRRequests, CurrencyCode = sellJourneyByKeyRequestData.CurrencyCode }, TypeOfSale = Mapper.Map <TypeOfSale>(sellJourneyByKeyRequestData.TypeOfSale), PriceItineraryBy = PriceItineraryBy.JourneyBySellKey, SellByKeyRequest = Mapper.Map <SellJourneyByKeyRequestData>(sellJourneyByKeyRequestData, m => m.AfterMap(SetFareTypes)) }; var stopWatch = _perfLogSettings.EnableNavApiLogging ? Stopwatch.StartNew() : null; var response = await _client.GetItineraryPriceAsync(new PriceItineraryRequest { ContractVersion = _navApiContractVer, MessageContractVersion = _navMsgContractVer, Signature = signature, EnableExceptionStackTrace = false, ItineraryPriceRequest = priceItineraryRequest }); //_navApiContractVer, false, //_navMsgContractVer, signature, priceItineraryRequest); if (_perfLogSettings.EnableNavApiLogging && stopWatch != null) { stopWatch.Stop(); var msecs = stopWatch.ElapsedMilliseconds; _logger.WriteTimedLog(msecs, "BookingManager.GetItineraryPriceAsync" + "|" + signature); } return(Mapper.Map <dto.PriceItinararyResponse>(response.Booking)); }
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); }
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); }