private Dictionary <string, decimal> GetLowestAdultFarePerPax(OneDayJourneySegment segmentItem)
        {
            Dictionary <string, decimal> lowestFare = new Dictionary <string, decimal>();

            if (segmentItem != null)
            {
                List <FlightFare> adultNonSoldOutFares = segmentItem.Flights.SelectMany(f => f.FlightFares).Where(ff => !ff.IsSoldOut(searchCriteria.Adults + searchCriteria.Children) && ff.PassengerTypeId == Enums.PassengerTypes.Adult).ToList();
                if (adultNonSoldOutFares != null && adultNonSoldOutFares.Count() > 0)
                {
                    lowestFare.Add("lowestAdultFarePerPax", adultNonSoldOutFares.Min(ff => ff.WebFareAmount));
                    lowestFare.Add("lowestAdultBaseFarePerPax", adultNonSoldOutFares.Min(ff => ff.DisplayAmountNoTaxes));
                    lowestFare.Add("lowestAdultTaxPerPax", adultNonSoldOutFares.Min(ff => ff.Taxes));
                }
            }

            return(lowestFare);
        }
        public List <Flights> BuildFlights(OneDayJourneySegment segmentItem, bool IsRerpice)
        {
            List <Flights> flights = new List <Flights>();

            if (segmentItem != null)
            {
                List <Flight> flightList = new List <Flight>();
                flightList = segmentItem.Flights.OrderBy(x => GetCheapflightFare(x.FlightFares)).ThenBy(x => x.Duration)//.ThenBy(x => x.GetUtcDepartureDate())
                             .ToList();

                foreach (var flightItem in flightList)
                {
                    Flights flight = new Flights();
                    flight.Origin        = flightItem.Origin;
                    flight.Dest          = flightItem.Destination;
                    flight.LfId          = Convert.ToString(flightItem.LFID);
                    flight.DepartureDate = flightItem.DepartureDate.ToString();
                    flight.ArrivalTime   = String.Format("{0:s}", flightItem.ArrivalDate);
                    flight.DepartureTime = String.Format("{0:s}", flightItem.DepartureDate);
                    flight.Stops         = BuildStops(flightItem);
                    if ((int)flightItem.Duration.TotalHours > 9)
                    {
                        flight.TotalDuration = string.Format("{0}:{1:mm}", (int)flightItem.Duration.TotalHours, flightItem.Duration);
                    }
                    else
                    {
                        flight.TotalDuration = string.Format("{0:hh}:{1:mm}", flightItem.Duration, flightItem.Duration);
                    }
                    flight.IsAvailabile = flightItem.FlightFares.Any(x => !x.IsSoldOut(searchCriteria.Adults + searchCriteria.Children));
                    flight.Legs         = BuildLegs(flightItem);
                    flight.FareTypes    = BuildFares(flightItem, IsRerpice);
                    flight.FlightNum    = flightItem.FlightNum;
                    flights.Add(flight);
                }
            }
            return(flights);
        }
        public List <Segments> BuildResponse(Model.Results.FlightResults response, Model.Search.SearchCriteria searchCriteria, Model.SecurityData securityData)
        {
            this.searchCriteria = searchCriteria;
            this._securityData  = securityData;
            List <Segments> segments = new List <Segments>();

            if (response.OneDayItineraries != null && response.OneDayItineraries.Count > 0)
            {
                currency = response.OneDayItineraries.First().CurrentDisplayCurrency;
                for (int i = 0; i < response.OneDayItineraries.Count(); ++i)
                {
                    OneDayJourneySegment segmentItem = response.OneDayItineraries[i];
                    Segments             segment     = new Segments();
                    segment.Origin        = segmentItem.Origin;
                    segment.Dest          = segmentItem.Destination;
                    segment.CurrencyCode  = currency;
                    segment.DepartureDate = String.Format("{0:s}", segmentItem.Date);
                    segment.Direction     = searchCriteria.Flights[i].FlightDirection.ToLower() == Direction.multiSector.ToString().ToLower() ? Direction.multiSector : searchCriteria.Flights[i].FlightDirection.ToLower() == "inbound" ? Direction.inBound : Direction.outBound;
                    segment.Route         = string.Format("{0}_{1}", segment.Origin, segment.Dest);

                    segment.Flights = BuildFlights(segmentItem, false);
                    var distinctFareBrands = segment.Flights.SelectMany(x => x.FareTypes).Select(x =>
                                                                                                 new FareBrandInfo()
                    {
                        FareTypeID   = x.FareTypeID,
                        FareTypeName = x.FareTypeName,
                        CabinType    = x.Cabin.ToString(),
                        OrderId      = getFareOrderId(x.FareTypeID)
                    }
                                                                                                 ).GroupBy(fb => fb.FareTypeID).OrderBy(x => x.Key)
                                             .Select(g => g.First());


                    segment.Brands = new List <Brand>();
                    foreach (var brandInfo in distinctFareBrands.OrderBy(a => a.OrderId))
                    {
                        segment.Brands.Add(new Brand
                        {
                            FareTypeID       = brandInfo.FareTypeID.ToString(),
                            Cabin            = brandInfo.CabinType.ToUpper() == "BUSINESS" ? Cabin.business : brandInfo.CabinType.ToUpper() == "ECONOMY" ? Cabin.economy : Cabin.first,
                            Name             = Constants.FareBrandIds.Where(x => x.Key == brandInfo.FareTypeName).FirstOrDefault().Value,
                            IncludedServices = BuildBrandIncludeServices(response.BrandedFareInfo, segmentItem.JourneySegmentId, brandInfo.FareTypeID.ToString()),
                            OrderId          = brandInfo.OrderId
                        });
                    }
                    segment.Notifications = new List <Notification>();
                    if (segment.Flights.Count == 0)
                    {
                        //ExceptionMessage message = (ExceptionMessage)_exceptionResourceManager.GetObject("NoFlights");
                        segment.Notifications.Add(new Notification
                        {
                            CmsKey         = "NoFlights",
                            DefaultMessage = "NoFlights",
                            DisplayLevel   = "S"
                        });
                    }

                    segment.MultiDayFlights = BuildMultiDaySegments(response.MultiDayItineraries.Where(a => a.JourneySegmentId == segmentItem.JourneySegmentId).ToList(), 7);

                    segments.Add(segment);
                }
            }

            return(segments);
        }