Skip to content

Instantly share code, notes, and snippets.

@mqamarmunir
Created January 31, 2023 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mqamarmunir/ba956dc85cd8c63acb705f8c9a30cf3b to your computer and use it in GitHub Desktop.
Save mqamarmunir/ba956dc85cd8c63acb705f8c9a30cf3b to your computer and use it in GitHub Desktop.
// -----------------------------------------------------------------------
// <copyright file="PriceTicketedPnrCommandHandler.cs" company="Calrom Limited">
// Copyright (c) Calrom Limited. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------
namespace Calrom.Bookings.Api.Application.Commands
{
using System.Collections.Generic;
using System.Text;
using Calrom.Aurora.Messages;
using Calrom.Bookings.Api.Application.Comparers;
using Calrom.Bookings.Api.Application.Queries.ViewModels;
using Calrom.Bookings.Domain;
using Calrom.Bookings.Domain.Book;
using Calrom.Bookings.Domain.Clients;
using Calrom.Bookings.Domain.Models;
using Calrom.Bookings.Domain.Repositories;
using Calrom.Bookings.Domain.User;
using Calrom.Bookings.Domain.ValueObjects;
using Calrom.Bookings.Infrastructure.ElasticSearch;
using Calrom.Bookings.Infrastructure.Repositories;
using MassTransit;
using Microsoft.Extensions.Logging;
using Enum = System.Enum;
using ResponseInfo = Calrom.Bookings.Domain.ValueObjects.ResponseInfo;
/// <summary>
/// Price pnr command handler for existing pnr.
/// </summary>
public class PriceTicketedPnrCommandHandler : IPriceTicketedPnrCommandHandler
{
private readonly IAmendService amendService;
private readonly ICreateCommandRequestConverter requestConverter;
private readonly IPublishEndpoint publishEndpoint;
private readonly IUserAccessor userAccessor;
private readonly IBookingRepository bookingRepository;
private readonly ICabinRepository cabinRepository;
private readonly IPnrRepository pnrRepository;
private readonly IFareFamilyRepository fareFamilyRepository;
private readonly ILogger<AmendPnrCommandHandler> logger;
private readonly ICalculatePricingPoliciesClient calculateClient;
private readonly IElasticSearchIndexer elasticSearchIndexer;
/// <summary>
/// Initializes a new instance of the <see cref="PriceTicketedPnrCommandHandler" /> class.
/// </summary>
/// <param name="amendService">A service responsible for handling amendments to bookings.</param>
/// <param name="requestConverter">A converter used to convert incoming request data into a format usable by the amendment service.</param>
/// <param name="publishEndpoint">An endpoint or URL used to publish or send amended booking data.</param>
/// <param name="userAccessor">An accessor used to retrieve information about the user making the request.</param>
/// <param name="bookingRepository">A repository used to access and retrieve booking data.</param>
/// <param name="pnrRepository">A repository used to access and retrieve passenger name record (PNR) data.</param>
/// <param name="fareFamilyRepository">A repository used to access and retrieve fare family data.</param>
/// <param name="calculateClient">A client used to calculate the fare for the amended booking.</param>
/// <param name="cabinRepository">A repository used to access and retrieve cabin data.</param>
/// <param name="elasticSearchIndexer">A service used to index the amended booking data in an Elasticsearch index.</param>
/// <param name="noteCommandHandler">The note command handler.</param>
/// <param name="logger">A logger used to log events and errors related to the `PriceTicketedPnrCommandHandler` class.</param>
public PriceTicketedPnrCommandHandler(
IAmendService amendService,
ICreateCommandRequestConverter requestConverter,
IPublishEndpoint publishEndpoint,
IUserAccessor userAccessor,
IBookingRepository bookingRepository,
IPnrRepository pnrRepository,
IFareFamilyRepository fareFamilyRepository,
ICabinRepository cabinRepository,
ICalculatePricingPoliciesClient calculateClient,
IElasticSearchIndexer elasticSearchIndexer,
IAddNoteCommandHandler noteCommandHandler,
ILogger<AmendPnrCommandHandler> logger)
{
this.amendService = amendService;
this.requestConverter = requestConverter;
this.publishEndpoint = publishEndpoint;
this.bookingRepository = bookingRepository;
this.pnrRepository = pnrRepository;
this.fareFamilyRepository = fareFamilyRepository;
this.cabinRepository = cabinRepository;
this.calculateClient = calculateClient;
this.userAccessor = userAccessor;
this.logger = logger;
this.elasticSearchIndexer = elasticSearchIndexer;
}
/// <summary>
/// Price async command.
/// </summary>
/// <param name="repriceTicketedPnr">The re price ticketed pnr contract.</param>
/// <returns>Create response.</returns>
public async Task<Contracts.CreateResponse> HandleAsync(Calrom.Aurora.Messages.RepriceTicketedPnr repriceTicketedPnr)
{
try
{
var responseInfos = new ResponseInfos();
var pnr = await this.pnrRepository.GetFullPnrAsync(repriceTicketedPnr.PnrId);
var domainRequest = this.requestConverter.ConvertRequest(repriceTicketedPnr.AmendRequest, pnr);
domainRequest.AmendRequestType = Domain.Gds.Request.AmendRequestTypes.PostTicket;
//// Set pnr notes
await this.SetDomainRequestNotes(repriceTicketedPnr.PnrId, domainRequest);
// get booking
var bookingDataAggregate = await this.bookingRepository.GetAsync(repriceTicketedPnr.BookingId);
domainRequest.SetBookingReference(bookingDataAggregate.BookingReference);
// Call pricing policy
var pricingPoliciesResponse = await this.GetPricingPoliciesClientRequest(pnr, domainRequest.Notes.ToList(), bookingDataAggregate.RevenueStreamId, bookingDataAggregate.CurrencyId, repriceTicketedPnr.AmendRequest.PriceOption.FareTypeId);
var isAmendPricingBookedDate = false;
if (pricingPoliciesResponse == null)
{
//// no response got from the pricing policies service.
this.logger.LogError("Unable to get the pricing policies response for {revenueStreamId}", bookingDataAggregate.RevenueStreamId);
responseInfos.Add(ResponseInfo.CreateError(ResponseInfoCodes.UnableToGetPricingPoliciesRules.Id, $"Unable to get the pricing policies rules for revenue stream id: {bookingDataAggregate.RevenueStreamId} from {pnr.GdsId}."));
}
else
{
SetPricingPolicies(domainRequest, pricingPoliciesResponse, bookingDataAggregate.RevenueStreamId, ref isAmendPricingBookedDate);
}
// populate generic cabin id into flights
await this.PopulateGenericCabinId(pnr.Flights);
// identify deleted flights
var domainDeletedFlights = IdentifyDeleteFlights(pnr.Flights, domainRequest.Routes, includeMarriedFlights: true).ToList();
domainRequest.DeleteFlights = domainDeletedFlights;
// identify new flights
domainRequest.AddRoutes = IdentifyNewRoutes(pnr.Flights, domainRequest.Routes);
var response = await this.amendService.AmendAsync(domainRequest);
responseInfos.AddRange(response.ResponseInfos);
var missingFlightIds = FindMissingMarriedFlights(pnr.Flights, domainDeletedFlights);
if (missingFlightIds.Any())
{
responseInfos.Add(new ResponseInfo(ResponseInfoTypes.Error, ResponseInfoCodes.MissingMarriedFlights.Id, $"{missingFlightIds.ToArray()}, are the married flights that are missing in the request."));
}
if (!responseInfos.HasErrors())
{
if (response.PriceOption != null)
{
PopulateLocations(domainRequest.Routes);
var addedFlights = domainRequest.AddRoutes.GetFlights().ToList();
// Update flight details
UpdateFlightDetails(response.Routes.GetFlights().ToList(), addedFlights);
// identify missing married flights
IdentifyMissingMarriedFlights(pnr.Flights, domainRequest.AddRoutes, domainDeletedFlights, domainRequest.AddRoutes.ToList());
var deletedFlightIds = domainDeletedFlights.Select(x => x.FlightId).ToArray();
var intactFlights = pnr.Flights.Where(x => !deletedFlightIds.Contains(x.FlightId)).ToList();
// remove sectors
if (domainDeletedFlights.Any())
{
this.pnrRepository.RemoveSectorsAsync(domainDeletedFlights);
}
// add sectors
if (addedFlights.Any())
{
await this.pnrRepository.AddSectorsAsync(pnr.Id, addedFlights);
}
// update fare families
////await this.UpdateFareFamilies(response.PriceOption, domainDeletedFlights, intactFlights);
await this.pnrRepository.UpdateCostingEntries(pnr.Id, domainRequest.PriceOption.PassengerTypeCostingEntries);
await this.pnrRepository.UpdateTaxLines(pnr.Id, domainRequest.PriceOption.TaxLines);
var noteText = GetAmendNote(addedFlights, domainDeletedFlights);
var notes = new List<Note>
{
new Note(noteText, DateTime.Now.Date, this.userAccessor.GetUserId(), NoteTypes.BOKAMD.ToString(), DateTime.Now, null),
};
await this.pnrRepository.AddNotesRangeAsync(pnr.Id, notes);
await this.pnrRepository.UnitOfWork.SaveEntitiesAsync();
}
//// raise price existing pnr completed event.
await this.publishEndpoint.Publish(new PriceExistingPnrCompleted(
repriceTicketedPnr.OperationId,
pnr.BookingId,
GetEventPassengers(repriceTicketedPnr.AmendRequest.Passengers),
Convert.ToDateTime(pnr.BookedDate),
GetTotalCostingEntryAmount(domainRequest.PriceOption.PassengerTypeCostingEntries.ToList(), response.PriceOption?.PassengerTypeCostingEntries.ToList()!, domainRequest.Passengers),
pnr.CreatorDetail?.CreatorOfficeId ?? string.Empty,
new List<Contracts.Note>(),
GetSearchOfferEvent(response.SearchOffer),
null));
}
else
{
await this.publishEndpoint.Publish(new PriceExistingPnrFailed(
repriceTicketedPnr.OperationId,
repriceTicketedPnr.BookingId,
bookingDataAggregate.BookingReference,
repriceTicketedPnr.PnrId,
pnr.PnrIdentification.PnrReference,
response.ResponseInfos));
this.logger.PricingBookingGdsResponseFailed(Enum.Parse<ServiceProviders>(pnr.GdsId!), response.ResponseInfos);
}
return new Contracts.CreateResponse(new ResponseInfos(response.ResponseInfos));
}
catch (Exception ex)
{
this.logger.LogException("Unhandled exception occurred in repricing ticketed pnr.", ex);
return new Contracts.CreateResponse(new ResponseInfos
{
ResponseInfo.CreateError(ResponseInfoCodes.PriceBookingException.Id, $"Error occurred during pricing the existing booking for amend tickets with booking id: {repriceTicketedPnr.BookingId}, and pnr id: {repriceTicketedPnr.PnrId}."),
});
}
}
private static string GetAmendNote(List<Flight> addFlights, List<Flight> deleteFlights)
{
var note = new StringBuilder();
note.Append("Amend booking part operation has completed successfully." + Environment.NewLine);
// Deleted flights
if (deleteFlights != null && deleteFlights.Count() > 0)
{
note.Append("Flights deleted:" + Environment.NewLine);
note.Append(GetItineraryString(deleteFlights) + Environment.NewLine);
}
// Added flights
if (addFlights != null && addFlights.Count() > 0)
{
note.Append("Flights added:" + Environment.NewLine);
note.Append(GetItineraryString(addFlights));
}
return note.ToString();
}
private static string GetItineraryString(IEnumerable<Flight> originDestinations)
{
if (originDestinations != null && originDestinations.Count() > 0)
{
List<string>? flightStrings = null;
int i = 0;
flightStrings = originDestinations.Select((x) =>
{
if (x == null)
{
return string.Empty;
}
i++;
string flightDetail = string.Empty;
string genericCabin = string.Empty;
string flightClass = string.Empty;
string flightClassAvailability = string.Empty;
string fare = string.Empty;
var flight = x;
if (flight != null)
{
flightDetail = flight.FlightDetail.ToString();
genericCabin = flight.GenericCabinId ?? string.Empty;
flightClass = flight.FlightClassId ?? string.Empty;
if (flight.FlightPassengerTypeDetails != null && flight.FlightPassengerTypeDetails.Where(f => f != null).Count() > 0)
{
var flightFare = flight.FlightPassengerTypeDetails.Where(f => f != null).FirstOrDefault(f => f.PassengerTypeId != null && f.PassengerTypeId == PassengerTypes.ADT.ToString());
if (flightFare != null)
{
fare = string.Format("{0} {1}", flightFare.FareBasisCode, flightFare.FareAmount);
}
}
}
// MAN-LHR 15-Feb-2012 15-Feb-2012 BA1506 BA ECO(Y) Y9
return string.Format(
"{0}{1}: {2}-{3} {4:dd-MMM-yyyy} {5:dd-MMM-yyyy} {6} {7}({8}) {9} {10}",
"FL",
i,
x.DepartureAirportId,
x.ArrivalAirportId,
x.DepartureDateTime,
x.ArrivalDateTime,
flightDetail,
genericCabin,
flightClass,
flightClassAvailability,
fare);
}).ToList();
return string.Join(Environment.NewLine, flightStrings).Replace(",", string.Empty);
}
return string.Empty;
}
private static void UpdateFlightDetails(List<Domain.Models.Flight> flights, List<Domain.Models.Flight> addedFlights)
{
FlightComparer flightComparer = new FlightComparer();
foreach (var flightToUpdate in addedFlights)
{
var flight = flights.FirstOrDefault(x => flightComparer.Equals(flightToUpdate, x));
if (flight != null)
{
flightToUpdate.SetAirlineCabin(flight.AirlineCabinId!);
flightToUpdate.SetGdsReference(flight.GdsReference!);
flightToUpdate.SetFareFamilyOwner(flight.FareFamilyOwner);
flightToUpdate.DepartureDateTimeUtc = flight.DepartureDateTimeUtc;
flightToUpdate.ArrivalDateTimeUtc = flight.ArrivalDateTimeUtc;
var flightDetail = flight.FlightDetail;
if (flightDetail != null)
{
flightToUpdate.FlightDetail.SetFlightStatus(flightDetail.ConnectionStatus ?? FlightStatus.HLDNED);
flightToUpdate.FlightDetail.SetDuration(flightDetail.Duration);
if (flightDetail.TerminalInfo != null)
{
flightToUpdate.FlightDetail.SetTerminalInfo(flightDetail.TerminalInfo);
}
}
}
}
}
private static void PopulateLocations(IReadOnlyList<Domain.Models.Route> responseSelectedRoutes)
{
foreach (var route in from route in responseSelectedRoutes where route.Flights.Any() select route)
{
if (route.DepartureLocationId == null)
{
route.SetDepartureLocationId(route.Flights.FirstOrDefault()!.DepartureAirportId);
}
if (route.ArrivalLocationId == null)
{
route.SetArrivalLocationId(route.Flights.LastOrDefault()!.ArrivalAirportId);
}
}
}
private static List<Domain.Models.Route> IdentifyNewRoutes(IReadOnlyList<Domain.Models.Flight> bookingPartFlights, IReadOnlyList<Domain.Models.Route> selectedRoutes)
{
FlightComparer flightComparer = new FlightComparer();
var selectedFlights = bookingPartFlights.ToList();
var addRoutes = new List<Domain.Models.Route>();
// identifying new routes and adding them to the addRoutes collection
foreach (var route in selectedRoutes.Where(x => x.Flights != null))
{
foreach (var flight in route.Flights)
{
// Exclude the Flown FLights
if (IsFlown(flight))
{
continue;
}
// compare and add flights
CompareFlights(flightComparer, selectedFlights, addRoutes, route, flight);
}
}
return addRoutes.OrderBy(x => x.DepartureDateTime).ToList();
}
private static void CompareFlights(FlightComparer flightComparer, List<Domain.Models.Flight> selectedFlights, List<Domain.Models.Route> addRoutes, Domain.Models.Route route, Domain.Models.Flight flight)
{
if (!selectedFlights.Any(x => flightComparer.Equals(flight, x)))
{
var addRoute = addRoutes.FirstOrDefault(x => x.RouteId == route.RouteId);
if (addRoute == null)
{
addRoute = route;
addRoutes.Add(addRoute);
}
}
}
private static bool IsFlown(Domain.Models.Flight flight)
{
return flight.DepartureDateTime < DateTime.Now;
}
private static void SetPricingPolicies(Domain.Contracts.AmendRequest amendRequest, CalculatePricingPolicies pricingPoliciesResponse, string revenueStreamId, ref bool isAmendPricingBookedDate)
{
amendRequest.PricingPolicies = pricingPoliciesResponse!.PricingResponse.FirstOrDefault(x => x.Key == revenueStreamId).Value;
if (amendRequest.PricingPolicies != null)
{
isAmendPricingBookedDate = IsAmendmentPricingBookedDate(amendRequest.PricingPolicies);
if (isAmendPricingBookedDate)
{
amendRequest.OverrideBookingDate = amendRequest.PricingPolicies.PricingDate;
}
}
}
private static bool IsAmendmentPricingBookedDate(PricingResponse pricingPolicies)
{
if (pricingPolicies != null && !string.IsNullOrEmpty(pricingPolicies.PreTicketAmendRuleType))
{
return true;
}
return false;
}
private static SearchOfferEvent? GetSearchOfferEvent(SearchOffer? searchOffer)
{
if (searchOffer != null)
{
return new SearchOfferEvent(searchOffer.ResponseId, searchOffer.OfferId, searchOffer.Owner, searchOffer.OfferItemIds);
}
return null;
}
private static List<PassengerEvent> GetEventPassengers(IEnumerable<Contracts.Passenger> passengers)
{
var responseEventPassengers = new List<PassengerEvent>();
foreach (var passenger in passengers)
{
responseEventPassengers.Add(new PassengerEvent(
passenger.PassengerId.ToString(),
passenger.Title,
passenger.Firstname,
passenger.Surname,
passenger.PassengerTypeId,
passenger.LinkedPassengerId?.ToString(),
passenger.DateOfBirth));
}
return responseEventPassengers;
}
private static decimal GetTotalCostingEntryAmount(
IList<PassengerTypeCostingEntry> requestPassengerTypeCostingEntries,
IList<PassengerTypeCostingEntry> responsePassengerTypeCostingEntries,
IReadOnlyList<Domain.Models.Passenger> passengers)
{
return responsePassengerTypeCostingEntries != null
? GetAmount(responsePassengerTypeCostingEntries, passengers)
: GetAmount(requestPassengerTypeCostingEntries, passengers);
}
private static decimal GetAmount(IList<PassengerTypeCostingEntry> passengerTypeCostingEntries, IReadOnlyList<Domain.Models.Passenger> passengers)
{
var costingEntryTypes = new List<CostingEntryType> { CostingEntryType.NetFare, CostingEntryType.TaxEntry, };
decimal amount = 0;
foreach (var costingEntryType in costingEntryTypes)
{
foreach (var costing in passengerTypeCostingEntries.Where(x => x.CostingEntryTypeId == costingEntryType.Id))
{
var passengerCount = passengers.Count(x => x.PassengerTypeId == costing.PassengerTypeId);
amount += passengerCount * costing.EntryAmount;
}
}
return amount;
}
private static PricingPoliciesClientRequest GetPricingPoliciesClientRequest(PnrViewModel bookingPnr, string revenueStreamId)
{
NoteViewModel? GetNote(NoteTypes noteType)
{
return bookingPnr.Notes.FirstOrDefault(x => x.NoteTypeId == noteType.ToString());
}
return new PricingPoliciesClientRequest
{
RevenueStreamId = revenueStreamId,
CurrencyId = bookingPnr.Cost.CurrencyId,
FareTypeId = bookingPnr.FareTypeId,
GdsId = bookingPnr.GdsId!,
Stage = Stages.TKET,
PnrReference = bookingPnr.PnrReference,
BookingDate = bookingPnr.BookedDate?.ToLocalTime(),
LastQuotedDate = (GetNote(NoteTypes.LSTQCD)?.NoteDate ?? bookingPnr.LastQuotedDate)?.ToLocalTime(),
LastVoluntryDate = GetNote(NoteTypes.VLTYCD)?.NoteDate,
PnrCreationDate = bookingPnr.PnrCreationDate?.ToLocalTime(),
};
}
private static IReadOnlyList<Domain.Models.Flight> IdentifyDeleteFlights(IReadOnlyList<Domain.Models.Flight> bookingPartFlights, IReadOnlyList<Domain.Models.Route> selectedRoutes, bool includeMarriedFlights = false)
{
FlightComparer flightComparer = new FlightComparer();
var deleteFlights = new List<Domain.Models.Flight>();
// Checking if there are any flights in the booking which aren't on the selected routes list
if (selectedRoutes.Count == 0)
{
deleteFlights = bookingPartFlights.OrderBy(x => x.DepartureDateTime).ToList();
return deleteFlights;
}
var selectedFlights = selectedRoutes.GetFlights().ToList();
// Checking if there are any flights in the booking which aren't on the selected routes list.
// It means they have to be deleted
foreach (var flight in bookingPartFlights)
{
if (!selectedFlights.Any(x => flightComparer.Equals(flight, x)))
{
deleteFlights.Add(flight);
}
}
if (includeMarriedFlights && deleteFlights.IsAny())
{
var missingFlights = new List<Domain.Models.Flight>();
foreach (var deleteFlight in deleteFlights.Select(deleteFlight => deleteFlight.MarriedRouteId))
{
if (!deleteFlight.HasValue)
{
continue;
}
missingFlights.AddRange(bookingPartFlights.Where(flight => flight.MarriedRouteId == deleteFlight));
}
deleteFlights.AddRange(missingFlights);
}
return deleteFlights.Distinct().OrderBy(x => x.DepartureDateTime).ToList();
}
private static void IdentifyMissingMarriedFlights(IReadOnlyList<Domain.Models.Flight> bookingPartFlights, IReadOnlyList<Domain.Models.Route> selectedRoutes, IReadOnlyList<Domain.Models.Flight> deletedFlights, List<Domain.Models.Route> addedRoutes)
{
if (deletedFlights.IsAny())
{
FlightComparer flightComparer = new FlightComparer();
var selectedFlights = selectedRoutes.GetFlights();
var addedFlights = addedRoutes.GetFlights();
// Get any existing flights that are not changed
var flights = bookingPartFlights.Except(deletedFlights, flightComparer).ToList();
// Add any added flights
flights.AddRange(addedFlights);
// Find any flights that are in the selectedFlights that not existing or new
_ = selectedFlights.Except(flights, flightComparer).ToList();
}
}
private static bool IsExpired(DateTime? expiredDate)
{
return expiredDate.HasValue && expiredDate.Value <= DateTime.Now;
}
private static List<string> FindMissingMarriedFlights(IReadOnlyList<Domain.Models.Flight> bookingPartFlights, List<Domain.Models.Flight> deleteFlights)
{
List<string> missingFlightIds = new List<string>();
if (deleteFlights.IsAny())
{
foreach (var flight in bookingPartFlights)
{
var deletedflights = deleteFlights.Where(i => i.FlightId == flight.FlightId).ToList();
deletedflights.ForEach(x => x.MarriedRouteId = flight.MarriedRouteId);
}
var marriedFlights = bookingPartFlights.Where(x => deleteFlights.Exists(y => y.MarriedRouteId != null && y.MarriedRouteId == x.MarriedRouteId));
missingFlightIds = marriedFlights.Where(x => !deleteFlights.Exists(y => y.FlightId == x.FlightId)).Select(e => "Flight ID: " + e.FlightId.ToString() + " Itenery: " + e.DepartureAirportId + "-" + e.ArrivalAirportId).ToList();
}
return missingFlightIds;
}
////private async Task UpdateFareFamilies(Contracts.PriceOption priceOption, List<Domain.Models.Flight> deletedFlights, List<Domain.Models.Flight> intactFlights)
////{
//// //// Updated fare family ids from price option flights
//// List<Guid> updatedFareFamilyIds = new List<Guid>();
//// foreach (var fareFamily in priceOption.FareFamilies.Distinct())
//// {
//// updatedFareFamilyIds.Add(fareFamily.FareFamilyId);
//// }
//// var bptfareFamilyIds = deletedFlights.SelectMany(x => x.FlightPassengerTypeDetails!.Select(y => y.FareFamilyId)).Where(x => x != Guid.Empty);
//// // check if there is any difference between database fare families and price option flights fare families
//// // if yes then update fare families and delete existing, if not then no need to update and delete existing fare families
//// bool isfarefamilyupdated = bptfareFamilyIds.Except(updatedFareFamilyIds).Concat(updatedFareFamilyIds.Except(bptfareFamilyIds)).IsAny();
//// if (isfarefamilyupdated)
//// {
//// await this.SaveFareFamilies(priceOption);
//// var intactbptFareFamilyIds = intactFlights.SelectMany(x => x.FlightPassengerTypeDetails!.Select(y => y.FareFamilyId)).Where(x => x != Guid.Empty);
//// bptfareFamilyIds = bptfareFamilyIds.Except(intactbptFareFamilyIds);
//// foreach (var item in bptfareFamilyIds)
//// {
//// if (item != Guid.Empty)
//// {
//// await this.DeleteFareFamilyAndServiceMappings(item);
//// }
//// }
//// }
////}
private async Task SetDomainRequestNotes(Guid pnrId, Domain.Contracts.AmendRequest amendRequest)
{
var notes = await this.pnrRepository.GetNoteAsync(
pnrId,
new List<string>
{
NoteTypes.VLTYCD.ToString(),
NoteTypes.LSTQCD.ToString(),
NoteTypes.BKPRTS.ToString(),
});
if (notes != null)
{
amendRequest.Notes.AddRange(notes);
}
}
private async Task PopulateGenericCabinId(List<Domain.Models.Flight> flights)
{
var cabins = await this.cabinRepository.GetAsync();
// populate generic cabin id
foreach (var bookFlight in flights)
{
cabins.TryGetValue(bookFlight.AirlineCabinId, out var cabin);
bookFlight.SetGenericCabin(cabin?.GenericCabinId);
}
}
private async Task<CalculatePricingPolicies> GetPricingPoliciesClientRequest(Pnr pnr, List<Domain.Models.Note> notes, string revenueStreamId, string currencyId, string fareTypeId)
{
Domain.Models.Note? GetNote(NoteTypes noteType)
{
return notes.FirstOrDefault(x => x.ActionType == noteType.ToString());
}
var pricingPoliciesRequest = new PricingPoliciesClientRequest
{
RevenueStreamId = revenueStreamId,
CurrencyId = currencyId,
FareTypeId = fareTypeId,
GdsId = pnr.GdsId!,
Stage = Stages.AMED,
PnrReference = pnr.PnrIdentification.PnrReference,
BookingDate = pnr.BookedDate,
LastQuotedDate = GetNote(NoteTypes.LSTQCD)?.NoteDate ?? pnr.LastQuoteDate,
LastVoluntryDate = GetNote(NoteTypes.VLTYCD)?.NoteDate,
PnrCreationDate = pnr.PnrCreationDate,
};
this.logger.PricingPoliciesClientRequest(
pricingPoliciesRequest.RevenueStreamId,
pricingPoliciesRequest.BookingDate,
pricingPoliciesRequest.LastQuotedDate,
pricingPoliciesRequest.PnrCreationDate,
pricingPoliciesRequest.PnrReference,
pricingPoliciesRequest.Stage);
return await this.calculateClient.CalculateAsync(pricingPoliciesRequest);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment