Esempio n. 1
0
        // search
        public ActionResult FlightSearch(FlightSearchModel model)
        {
            // check model
            if (model == null)
            {
                return(Notifization.Invalid(NotifizationText.Invalid));
            }

            int _adt = model.ADT; // Adults
            int _cnn = model.CNN; // minors
            int _inf = model.INF; // Infant

            bool     _isRoundTrip         = model.IsRoundTrip;
            string   _destinationLocation = model.DestinationLocation;
            string   _originLocation      = model.OriginLocation;
            DateTime _departureDateTime   = model.DepartureDateTime;
            DateTime?_returnDateTime      = model.ReturnDateTime;

            //
            if (_adt <= 0)
            {
                return(Notifization.Invalid("Adults must be > 0"));
            }
            //
            if (_inf > _adt)
            {
                return(Notifization.Invalid("Infant invalid"));
            }
            // create session
            SessionService sessionService = new SessionService();
            var            _session       = sessionService.GetSession();

            if (_session == null)
            {
                return(Notifization.NotService);
            }
            // get token
            string _token          = _session.Token;
            string _conversationId = _session.ConversationID;

            if (string.IsNullOrWhiteSpace(_token))
            {
                return(Notifization.NotService);
            }
            // seach data in web service
            AirAvailLLSRQService airAvailLLSRQService = new AirAvailLLSRQService();
            VNAFareLLSRQService  vNAFareLLSRQService  = new VNAFareLLSRQService();
            // Flight >> go
            // ****************************************************************************************************************************
            //
            var dataAirAvail = airAvailLLSRQService.FUNC_OTA_AirAvailLLSRQ(new AirAvailLLSRQModel
            {
                Token               = _token,
                ConversationID      = _conversationId,
                DepartureDateTime   = model.DepartureDateTime,
                DestinationLocation = model.DestinationLocation,
                OriginLocation      = model.OriginLocation
            });

            // check data
            if (dataAirAvail == null)
            {
                return(Notifization.NotService);
            }
            // search light data
            var lstOrigin = dataAirAvail.OriginDestinationOptions.OriginDestinationOption.ToList();

            if (lstOrigin.Count == 0)
            {
                return(Notifization.NotFound(NotifizationText.NotFound));
            }
            // attachment INF (em bé)
            int _passengerTotal = model.ADT + model.CNN + model.INF;
            //  passenger total is availability
            int _availabilityTotal = model.ADT + model.CNN;
            //
            //var _availabilityData =   List<>
            string _flightGo    = model.OriginLocation;
            string _flightTo    = model.DestinationLocation;
            var    fareLLSModel = new FareLLSModel
            {
                Token               = _token,
                ConversationID      = _conversationId,
                DepartureDateTime   = _departureDateTime,
                DestinationLocation = _flightTo,
                OriginLocation      = _flightGo,
                AirlineCode         = "VN",
                PassengerType       = new List <string>()
            };

            if (model.ADT > 0)
            {
                fareLLSModel.PassengerType.Add("ADT");
            }
            if (model.CNN > 0)
            {
                fareLLSModel.PassengerType.Add("CNN");
            }
            if (model.INF > 0)
            {
                fareLLSModel.PassengerType.Add("INF");
            }
            //
            var dataFareLLS = vNAFareLLSRQService.FareLLS(fareLLSModel);

            if (dataFareLLS == null)
            {
                return(Notifization.Invalid(NotifizationText.Invalid));
            }
            // Fare
            string _currencyCode    = "VND";
            var    lstFlightSegment = new List <FlightSegment>();
            var    lstFlightSearch  = new List <FlightSearch>();
            int    _year            = model.DepartureDateTime.Year;

            foreach (var origin in lstOrigin)
            {
                //#1. Availability: get all Flight is Availability
                //#2.
                var _lstFlightSegment = origin.FlightSegment;
                if (_lstFlightSegment.Count() > 0)
                {
                    foreach (var flightSegment in _lstFlightSegment)
                    {
                        var _lstBookingClassAvail = flightSegment.BookingClassAvail;
                        if (_lstBookingClassAvail.Count() > 0)
                        {
                            foreach (var bookingClassAvail in _lstBookingClassAvail)
                            {
                                if (!string.IsNullOrWhiteSpace(bookingClassAvail.Availability) && int.Parse(bookingClassAvail.Availability) > _availabilityTotal)
                                {
                                    var    _datedepart       = DateTime.Parse(_year + "-" + flightSegment.DepartureDateTime + ":00");
                                    var    _arrivalDateTime  = _datedepart.AddMinutes(double.Parse(flightSegment.FlightDetails.TotalTravelTime));
                                    string _resBookDesigCode = bookingClassAvail.ResBookDesigCode;
                                    //  price model
                                    var flightCostDetails = GetFareDetails(new VNAFareLLSRQModel
                                    {
                                        FareLLS          = fareLLSModel,
                                        FareRSData       = dataFareLLS,
                                        CurrencyCode     = _currencyCode,
                                        ResBookDesigCode = _resBookDesigCode
                                    });
                                    if (flightCostDetails != null && flightCostDetails.Count > 0)
                                    {
                                        lstFlightSegment.Add(new FlightSegment
                                        {
                                            AirEquipType        = flightSegment.Equipment.AirEquipType,
                                            ArrivalDateTime     = Convert.ToString(_arrivalDateTime),
                                            DepartureDateTime   = Convert.ToString(_datedepart),
                                            DestinationLocation = _destinationLocation,
                                            FlightNo            = Convert.ToInt32(flightSegment.FlightNumber),
                                            FlightType          = (int)VNAEnum.FlightDirection.FlightGo,
                                            NumberInParty       = _availabilityTotal,
                                            OriginLocation      = _originLocation,
                                            PriceDetails        = flightCostDetails,
                                            ResBookDesigCode    = _resBookDesigCode,
                                            RPH = flightSegment.RPH
                                        });
                                    }
                                }
                                else
                                {
                                    continue;
                                }
                            }
                        }
                        else
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    continue;
                }
            }
            //
            if (lstFlightSegment.Count() == 0)
            {
                return(Notifization.NotFound(NotifizationText.NotFound));
            }
            lstFlightSearch.Add(new FlightSearch
            {
                TimeHanndle   = 1,
                ADT           = _adt,
                CNN           = _cnn,
                INF           = _cnn,
                FlightSegment = lstFlightSegment
            });
            return(Notifization.Data("OK", lstFlightSegment));
        }
Esempio n. 2
0
        // cost
        public ActionResult FlightCost(FlightSearchModel model)
        {
            // check model
            if (model == null)
            {
                return(Notifization.Invalid(NotifizationText.Invalid));
            }

            int _adt = model.ADT; // Adults
            int _cnn = model.CNN; // minors
            int _inf = model.INF; // Infant

            string   _destinationLocation = model.DestinationLocation;
            string   _originLocation      = model.OriginLocation;
            DateTime _departureDateTime   = model.DepartureDateTime;
            DateTime?_returnDateTime      = model.ReturnDateTime;

            //
            if (_adt <= 0)
            {
                return(Notifization.Invalid("Adults must be > 0"));
            }
            //
            if (_inf > _adt)
            {
                return(Notifization.Invalid("Infant invalid"));
            }
            // create session
            SessionService sessionService = new SessionService();
            var            _session       = sessionService.GetSession();

            if (_session == null)
            {
                return(Notifization.NotService);
            }
            // get token
            string _token          = _session.Token;
            string _conversationId = _session.ConversationID;

            if (string.IsNullOrWhiteSpace(_token))
            {
                return(Notifization.NotService);
            }
            // seach data in web service
            VNAFareLLSRQService vNAFareLLSRQService = new VNAFareLLSRQService();
            // Flight >> go
            // ****************************************************************************************************************************
            string _flightGo    = model.OriginLocation;
            string _flightTo    = model.DestinationLocation;
            var    fareLLSModel = new FareLLSModel
            {
                Token               = _token,
                ConversationID      = _conversationId,
                DepartureDateTime   = _departureDateTime,
                DestinationLocation = _flightTo,
                OriginLocation      = _flightGo,
                AirlineCode         = "VN",
                PassengerType       = new List <string>()
            };

            if (model.ADT > 0)
            {
                fareLLSModel.PassengerType.Add("ADT");
            }
            if (model.CNN > 0)
            {
                fareLLSModel.PassengerType.Add("CNN");
            }
            if (model.INF > 0)
            {
                fareLLSModel.PassengerType.Add("INF");
            }
            //
            var dataFareLLS = vNAFareLLSRQService.FareLLS(fareLLSModel);

            if (dataFareLLS == null)
            {
                return(Notifization.Invalid(NotifizationText.Invalid));
            }
            //
            return(Notifization.Data("OK", dataFareLLS));
        }