예제 #1
0
        private List <Notification> ValidateRequest(Model.Search.SearchCriteria searchCriteria)
        {
            List <Notification> validationMessages = new List <Notification>();

            bool originEmpty      = searchCriteria.Flights.Any(x => string.IsNullOrEmpty(x.Origin));
            bool destinationEmpty = searchCriteria.Flights.Any(x => string.IsNullOrEmpty(x.Destination));

            if (originEmpty)
            {
                validationMessages.Add(BuildValidationMessage("OriginRequiredValidation"));
            }

            if (destinationEmpty)
            {
                validationMessages.Add(BuildValidationMessage("DestinationRequiredValidation"));
            }

            if (searchCriteria.Flights.Any(x => x.DepartureDate == null))
            {
                validationMessages.Add(BuildValidationMessage("DepartureDateRequiredValidation"));
            }


            if (searchCriteria.Flights.Count() == 2)
            {
                Model.Search.FlightCriteria inboundFlight  = searchCriteria.Flights.FirstOrDefault(f => f.FlightDirection == "inbound");
                Model.Search.FlightCriteria outboundFlight = searchCriteria.Flights.FirstOrDefault(f => f.FlightDirection == "outbound");
                if (inboundFlight != null && outboundFlight != null && inboundFlight.DepartureDate < outboundFlight.DepartureDate &&
                    inboundFlight.Origin == outboundFlight.Destination && inboundFlight.Destination == outboundFlight.Origin)
                {
                    validationMessages.Add(BuildValidationMessage("FlyingBackValidation"));
                }
            }

            if (searchCriteria.Adults + searchCriteria.Children > 9)
            {
                validationMessages.Add(BuildValidationMessage("TotalPassengerValidation"));
            }

            if (searchCriteria.Infants > searchCriteria.Adults)
            {
                validationMessages.Add(BuildValidationMessage("InfantPassengerValidation"));
            }

            //if (!string.IsNullOrEmpty(searchCriteria.PromoCode) && !Regex.IsMatch(searchCriteria.PromoCode, "^[A-Za-z0-9_]+$"))
            //{
            //    validationMessages.Add(BuildValidationMessage("PromoCodeValidation"));
            //}

            return(validationMessages);
        }
        public List <Segments> BuildIncludedServiceResponse(List <Model.Results.BrandedFareInfo> includes, Model.Search.SearchCriteria searchCriteria)
        {
            var brandList = GetBrandList();

            return(searchCriteria.Flights.Select(flt => new Segments()
            {
                Route = flt.Origin + "_" + flt.Destination,
                Origin = flt.Origin,
                Dest = flt.Destination,
                Direction = !string.IsNullOrEmpty(flt.FlightDirection) && flt.FlightDirection.ToLower() == "inbound" ? Direction.inBound : Direction.outBound,
                DepartureDate = String.Format("{0:s}", flt.DepartureDate),
                Brands = brandList != null ? brandList.Select(brandInfo => 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.FareTypeID).FirstOrDefault().Value,
                    IncludedServices = BuildBrandIncludeServices(includes, flt.SegmentId, brandInfo.FareTypeID.ToString()),
                    OrderId = brandInfo.OrderId
                }).ToList() : null
            }).ToList());
        }
        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);
        }
예제 #4
0
        public virtual async Task <HttpResponseMessage> Post(ApiFlightsPostRequest requestContent)
        {
            if (requestContent == null)
            {
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new Notification
                {
                    CmsKey = "GeneralExceptionMessage",
                    DefaultMessage = "Sorry there was a problem. Please try again.",
                    CanContinue = false
                }));
            }

            HttpStatusCode statusCode;
            var            flightCriteria = new List <Model.Search.FlightCriteria>();

            try
            {
                var searchCriteria = new Model.Search.SearchCriteria
                {
                    Adults   = requestContent.PaxInfo.AdultCount.Value,
                    Children = requestContent.PaxInfo.ChildCount.Value,
                    Infants  = requestContent.PaxInfo.InfantCount.Value,
                    Flights  = requestContent.SearchCriteria.Select((criteria, i) => new Model.Search.FlightCriteria
                    {
                        DepartureDate   = DateTime.ParseExact(criteria.Date, "M/d/yy hh:mm tt", CultureInfo.InvariantCulture),
                        Origin          = criteria.Origin,
                        Destination     = criteria.Dest,
                        FlightDirection = Convert.ToString(criteria.Direction).ToLower(),
                        SegmentId       = i + 1
                    }).ToList(),
                    PromoCode    = requestContent.PromoCode,
                    IsFlexible   = false,
                    CabinType    = requestContent.CabinClass ?? "",
                    CurrencyCode = requestContent.CurrencyCode
                };

                List <Notification> validationMessages = ValidateRequest(searchCriteria);
                List <Segments>     segments           = new List <Segments>();
                var    securityData = new SecurityData();
                object securityObj;
                Request.Properties.TryGetValue("securityData", out securityObj);
                securityData = (SecurityData)securityObj;

                if (validationMessages.Any())
                {
                    statusCode = HttpStatusCode.BadRequest;
                }
                else
                {
                    var segmentResults = await this._flightTask.GetFlightFareQuotes(searchCriteria, securityData);

                    segments   = new Builders.FlightSearchResultBuilder().BuildResponse(segmentResults, searchCriteria, securityData);
                    statusCode = HttpStatusCode.OK;
                }

                return(Request.CreateResponse(statusCode, new ApiFlightsPostOkResponse()
                {
                    Segments = segments,
                    Notifications = validationMessages
                }));
            }
            catch (Exception ex)
            {
                // Log exception details
                return(Request.CreateResponse(HttpStatusCode.BadRequest, new Notification
                {
                    CmsKey = "GeneralExceptionMessage",
                    DefaultMessage = "Sorry there was a problem. Please try again.",
                    CanContinue = false
                }));
            }
        }