public List <FareDetailsModel> GetFareDetails(VNAFareLLSRQModel model)
        {
            var dataFareLLS = model.FareRSData;
            List <WebService.WSFareLLSRQ.FareRSFareBasis> fareRSFareBases = dataFareLLS.FareBasis.ToList();

            if (fareRSFareBases == null || fareRSFareBases.Count == 0)
            {
                return(null);
            }
            //
            FareLLSModel fareLLSModel = model.FareLLS;

            if (fareLLSModel == null)
            {
                return(null);
            }
            //
            var lstFareLLSModel = fareLLSModel.PassengerType.ToList().OrderBy(m => m).ToList();

            if (lstFareLLSModel.Count == 0)
            {
                return(null);
            }
            //
            List <FareDetailsModel> fareDetailsModels = new List <FareDetailsModel>();

            //string test = "";
            foreach (var fareLLS in lstFareLLSModel)
            {
                List <FlightCost> flightCosts = new List <FlightCost>();
                int _cnt = 0;
                foreach (var fareRSFareBasis in fareRSFareBases)
                {
                    if (fareLLS == fareRSFareBasis.PassengerType[0].Code && fareRSFareBasis.AdditionalInformation.ResBookDesigCode == model.ResBookDesigCode && fareRSFareBasis.CurrencyCode == model.CurrencyCode)
                    {
                        //test += "| " + _cnt +":" + fareLLS;
                        double _total = 0.0;

                        if (!string.IsNullOrWhiteSpace(fareRSFareBasis.BaseFare.Amount) && Convert.ToDouble(fareRSFareBasis.BaseFare.Amount) > 0)
                        {
                            double _amount = Convert.ToDouble(fareRSFareBasis.BaseFare.Amount);
                            _total += _amount;
                            //
                            flightCosts.Add(new FlightCost
                            {
                                FareAmmout = _amount,
                                Total      = _total
                            });
                            fareDetailsModels.Add(new FareDetailsModel
                            {
                                RBH           = fareRSFareBasis.RPH,
                                PassengerType = fareLLS,
                                FareAmount    = _amount,
                                Code          = fareRSFareBasis.Code
                                                //ChargeDomesticFee = 0,
                                                //ScreeningFee = 0.0,
                                                //ServiceFee = 0.0,
                                                //Tax = 0.0,
                                                //Total = _total
                            });
                            _cnt++;
                        }
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            if (fareDetailsModels.Count == 0)
            {
                return(null);
            }
            //ok
            return(fareDetailsModels);
        }
        // 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));
        }
        // 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));
        }
        public AIRService.WebService.WSFareLLSRQ.FareRS FareLLS(FareLLSModel model)
        {
            try
            {
                #region wsdl
                AIRService.WebService.WSFareLLSRQ.MessageHeader messageHeader = new AIRService.WebService.WSFareLLSRQ.MessageHeader
                {
                    MessageData = new AIRService.WebService.WSFareLLSRQ.MessageData
                    {
                        Timestamp = DateTime.Now.ToString("s").Replace("-", "").Replace(":", "") + "Z"
                    },
                    ConversationId = model.ConversationID,
                    Service        = new AIRService.WebService.WSFareLLSRQ.Service(),
                    Action         = "FareLLSRQ",
                    From           = new AIRService.WebService.WSFareLLSRQ.From()
                };

                messageHeader.From.PartyId = new AIRService.WebService.WSFareLLSRQ.PartyId[1];
                var partyID = new AIRService.WebService.WSFareLLSRQ.PartyId
                {
                    Value = "WebServiceClient"
                };
                messageHeader.From.PartyId[0] = partyID;

                messageHeader.To = new AIRService.WebService.WSFareLLSRQ.To
                {
                    PartyId = new AIRService.WebService.WSFareLLSRQ.PartyId[1]
                };
                partyID = new AIRService.WebService.WSFareLLSRQ.PartyId
                {
                    Value = "WebServiceSupplier"
                };
                messageHeader.To.PartyId[0] = partyID;

                AIRService.WebService.WSFareLLSRQ.Security1 security = new AIRService.WebService.WSFareLLSRQ.Security1
                {
                    BinarySecurityToken = model.Token
                };
                AIRService.WebService.WSFareLLSRQ.FarePortTypeClient client = new AIRService.WebService.WSFareLLSRQ.FarePortTypeClient();
                AIRService.WebService.WSFareLLSRQ.FareRQ             fareRQ = new AIRService.WebService.WSFareLLSRQ.FareRQ
                {
                    OptionalQualifiers = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiers()
                };

                fareRQ.OptionalQualifiers.FlightQualifiers = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersFlightQualifiers
                {
                    VendorPrefs = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersFlightQualifiersAirline[1]
                };
                var VendorPrefs = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersFlightQualifiersAirline
                {
                    Code = model.AirlineCode
                };
                fareRQ.OptionalQualifiers.FlightQualifiers.VendorPrefs[0] = VendorPrefs;
                fareRQ.OptionalQualifiers.TimeQualifiers = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersTimeQualifiers
                {
                    TravelDateOptions = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersTimeQualifiersTravelDateOptions()
                };
                fareRQ.OptionalQualifiers.TimeQualifiers.TravelDateOptions.Start = model.DepartureDateTime.ToString("MM-dd");
                fareRQ.OptionalQualifiers.PricingQualifiers = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersPricingQualifiers
                {
                    PassengerType = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersPricingQualifiersPassengerType[model.PassengerType.Count]
                };
                var index = 0;
                fareRQ.OptionalQualifiers.PricingQualifiers.FareOptions = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersPricingQualifiersFareOptions
                {
                    Private = true
                };
                foreach (var item in model.PassengerType)
                {
                    var type = new AIRService.WebService.WSFareLLSRQ.FareRQOptionalQualifiersPricingQualifiersPassengerType
                    {
                        Code = item
                    };
                    fareRQ.OptionalQualifiers.PricingQualifiers.PassengerType[index] = type;
                    index++;
                }

                fareRQ.OriginDestinationInformation = new AIRService.WebService.WSFareLLSRQ.FareRQOriginDestinationInformation
                {
                    FlightSegment = new AIRService.WebService.WSFareLLSRQ.FareRQOriginDestinationInformationFlightSegment()
                };
                fareRQ.OriginDestinationInformation.FlightSegment.OriginLocation = new AIRService.WebService.WSFareLLSRQ.FareRQOriginDestinationInformationFlightSegmentOriginLocation
                {
                    LocationCode = model.OriginLocation
                };

                fareRQ.OriginDestinationInformation.FlightSegment.DestinationLocation = new AIRService.WebService.WSFareLLSRQ.FareRQOriginDestinationInformationFlightSegmentDestinationLocation
                {
                    LocationCode = model.DestinationLocation
                };
                var data = client.FareRQ(ref messageHeader, ref security, fareRQ);
                if (data.FareBasis == null || data.FareBasis.Count() == 0)
                {
                    return(null);
                }
                // ok
                return(data);

                #endregion
                #region xml
                //HttpWebRequest request = CreateWebRequest(URL_WS);
                //XmlDocument soapEnvelopeXml = new XmlDocument();
                //var path = HttpContext.Current.Server.MapPath(@"~/WS/Xml/Common.xml");
                //soapEnvelopeXml.Load(path);
                //soapEnvelopeXml.GetElementsByTagName("eb:Timestamp")[0].InnerText = DateTime.Now.ToString("yyyy-MM-dd'T'HH:mm:ss");
                //soapEnvelopeXml.GetElementsByTagName("eb:Service")[0].InnerText = "FareLLSRQ";
                //soapEnvelopeXml.GetElementsByTagName("eb:Action")[0].InnerText = "FareLLSRQ";
                //soapEnvelopeXml.GetElementsByTagName("eb:BinarySecurityToken")[0].InnerText = model.token;
                //soapEnvelopeXml.GetElementsByTagName("eb:ConversationId")[0].InnerText = model.ConversationId;
                //XmlDocument AddonXml = new XmlDocument();
                //XmlDocumentFragment child = soapEnvelopeXml.CreateDocumentFragment();
                //AddonXml.Load(path);
                //string xmlString = @"";
                //xmlString += "<FareRQ Version=\"2.9.0\" xmlns=\"http://webservices.sabre.com/sabreXML/2011/10\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">";
                //xmlString += "   <OptionalQualifiers>";
                //xmlString += "       <FlightQualifiers>";
                //xmlString += "           <VendorPrefs>";
                //xmlString += "               <Airline Code=\"VN\"/>";
                //xmlString += "           </VendorPrefs>";
                //xmlString += "       </FlightQualifiers>";
                //xmlString += "       <PricingQualifiers>";
                //foreach (var item in model.PassengerType)
                //{
                //    xmlString += "           <PassengerType Code=\"" + item + "\"/>";
                //}
                ////xmlString += "       <FareOptions Private=\"true\"/>";
                //xmlString += "       </PricingQualifiers>";
                //xmlString += "       <TimeQualifiers>";
                //xmlString += "           <TravelDateOptions Start=\"" + model.DepartureDateTime.ToString("MM-dd") + "\"/>";
                //xmlString += "       </TimeQualifiers>";
                //xmlString += "   </OptionalQualifiers>";
                //xmlString += "   <OriginDestinationInformation>";
                //xmlString += "       <FlightSegment>";
                //xmlString += "           <DestinationLocation LocationCode=\"" + model.DestinationLocation + "\"/>";
                //xmlString += "           <OriginLocation LocationCode=\"" + model.OriginLocation + "\"/>";
                //xmlString += "       </FlightSegment>";
                //xmlString += "   </OriginDestinationInformation>";
                //xmlString += "</FareRQ>";
                //child.InnerXml = xmlString;
                //soapEnvelopeXml.GetElementsByTagName("soapenv:Body")[0].AppendChild(child);
                ////soapEnvelopeXml.LoadXml(xmlString);
                //using (Stream stream = request.GetRequestStream())
                //{
                //    soapEnvelopeXml.Save(stream);
                //}
                ////var result = new AirFareByCityPairsResult();

                //using (WebResponse response = request.GetResponse())
                //{
                //    using (StreamReader rd = new StreamReader(response.GetResponseStream()))
                //    {
                //        string soapResult = rd.ReadToEnd();
                //        soapEnvelopeXml = new XmlDocument();
                //        soapEnvelopeXml.LoadXml(soapResult);
                //        return null;
                //    }
                //}

                #endregion
            }
            catch (Exception ex)
            {
                throw ex;


                return(null);
            }
        }