Beispiel #1
0
        public IEnumerable <Flight> GetFilteredFlights(string query = null, FlightSearchModel filter = null)
        {
            var flights = _unitOfWork.Flights.GetAllFlights()
                          .Where(fl => fl.IsDeleted != true);

            if (!String.IsNullOrWhiteSpace(query))
            {
                flights = flights.Where(g => g.Code.Contains(query));
            }
            if (filter.Departing.HasValue)
            {
                flights = flights.Where(t => t.Airports.Any(ar => ar.AirportId == filter.Departing &&
                                                            ar.DestinationPoint == true));
            }
            if (filter.Landing.HasValue)
            {
                flights = flights.Where(t => t.Airports.Any(ar => ar.AirportId == filter.Landing &&
                                                            ar.DestinationPoint == false));
            }
            if (filter.FlightStatus.HasValue)
            {
                flights = flights.Where(t => t.StatusId == filter.FlightStatus);
            }
            if (filter.Date.HasValue)
            {
                flights = flights.Where(t => t.Date.Day == filter.Date.Value.Day);
            }

            return(flights);
        }
Beispiel #2
0
        public LandingPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);

            flightService     = new DataService();
            flightSearchModel = new FlightSearchModel();
            flightSearchModel.GetFlightList().ContinueWith(task => BindFlightDetails(), TaskContinuationOptions.AttachedToParent);
        }
Beispiel #3
0
        public FlightListModel GetFlights(FlightSearchModel flightSearch)
        {
            var flightsResult = new FlightListModel();

            if (!DateTime.TryParse(flightSearch.DepartureDate, out DateTime departureDate))
            {
                throw new Exception("Failed to parse Departure date.");
            }

            if (_flightData != null && _flightData.Any())
            {
                //Roundtrip
                if (flightSearch.TripType.Equals("RT"))
                {
                    if ((!DateTime.TryParse(flightSearch.ReturnDate, out DateTime returnDate)))
                    {
                        throw new Exception("Failed to parse Return date.");
                    }

                    //Rountrip Query - Departing Flights
                    flightsResult.DepartingFlights = _flightData.Where(x => x.Origin.Equals(flightSearch.Origin, StringComparison.InvariantCultureIgnoreCase) &&
                                                                       x.Destination.Equals(flightSearch.Destination, StringComparison.InvariantCultureIgnoreCase) &&
                                                                       x.Departure.Date.Equals(departureDate.Date))
                                                     .OrderBy(x => x.Departure)
                                                     .ThenBy(x => x.FlightNumber)
                                                     .ThenBy(x => x.OriginName)
                                                     .ThenBy(x => x.Destination)
                                                     .ToList();

                    //Rountrip Query - Returning Flights
                    flightsResult.ReturningFlights = _flightData.Where(x => x.Origin.Equals(flightSearch.Destination, StringComparison.InvariantCultureIgnoreCase) &&
                                                                       x.Destination.Equals(flightSearch.Origin, StringComparison.InvariantCultureIgnoreCase) &&
                                                                       (x.Departure.Date > returnDate.Date && x.Departure.Date >= departureDate.Date))
                                                     .OrderBy(x => x.Departure)
                                                     .ThenBy(x => x.FlightNumber)
                                                     .ThenBy(x => x.OriginName)
                                                     .ThenBy(x => x.Destination)
                                                     .ToList();
                }
                else
                {
                    //One-Way
                    flightsResult.DepartingFlights = _flightData.Where(x => x.Origin.Equals(flightSearch.Origin, StringComparison.InvariantCultureIgnoreCase) &&
                                                                       x.Destination.Equals(flightSearch.Destination, StringComparison.InvariantCultureIgnoreCase) &&
                                                                       x.Departure.Date.Equals(departureDate.Date))
                                                     .OrderBy(x => x.Departure)
                                                     .ThenBy(x => x.FlightNumber)
                                                     .ThenBy(x => x.OriginName)
                                                     .ThenBy(x => x.Destination)
                                                     .ToList();
                }
            }
            return(flightsResult);
        }
Beispiel #4
0
        public ActionResult Post([FromBody] FlightSearchModel flightSearch)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState.Values));
            }

            //Returns a Collection of <Departing, Returning> Flights
            var result = _repository.GetFlights(flightSearch);

            return(Ok(result));
        }
Beispiel #5
0
        public MainPage()
        {
            InitializeComponent();
            NavigationPage.SetHasNavigationBar(this, false);

            flightService     = new DataService();
            flightSearchModel = new FlightSearchModel();

            flightSearchModel.StartDate  = DateTime.Now.Date;
            flightSearchModel.FlightList = CurrentFlight.Instance.AirlineList;
            BindingContext = flightSearchModel;
        }
        public SearchResultPage()
        {
            InitializeComponent();
            FlightSchedules.Add(new FlightScheduleInfo()
            {
                FlightScheduleId = 10
            });
            NavigationPage.SetHasNavigationBar(this, false);

            flightSearchModel = new FlightSearchModel();

            //BindingContext = this;
            BindingContext = flightSearchModel;

            //flightSearchModel.SelectedFlight = CurrentFlight.Instance.SelectedFlight;

            //Load Schedule for the selectedFlight and Date
            flightSearchModel.GetFlightSchedule(CurrentFlight.Instance.SelectedFlight, CurrentFlight.Instance.SelectedDate).ContinueWith((result) => { });
        }
Beispiel #7
0
        public ActionResult ShowFlights(string sortOrder, FlightSearchModel filter = null, string query = null)
        {
            ViewBag.NameSortParm   = String.IsNullOrEmpty(sortOrder) ? "name_desc" : "";
            ViewBag.DateSortParm   = sortOrder == "Date" ? "date_desc" : "Date";
            ViewBag.StatusSortParm = sortOrder == "Status" ? "status_desc" : "Status";

            var viewModel = new FlightsViewModel
            {
                Heading  = "All flights",
                Airports = _service.GetAllAirports(),
                Statuses = _service.GetAllStatuses(),
                Flights  = _service.SortFlight(_service.GetFilteredFlights(query, filter), sortOrder)
            };

            if (User.IsInRole(RoleName.Admin))
            {
                return(View("FlightsList", viewModel));
            }
            return(View("ReadOnlyFlightsList", viewModel));
        }
        public void Should_Return_Multiple_OneWay_Flights()
        {
            //Arrange
            var expected = 1;

            var flightSearchModel = new FlightSearchModel
            {
                TripType        = "OW",
                Origin          = "LGA",
                Destination     = "ATL",
                DepartureDate   = "2/9/2019",
                ReturnDate      = "2/10/2019",
                TotalPassengers = 1
            };

            //Act
            var actual = _repository.GetFlights(flightSearchModel).DepartingFlights.Count;


            //Assert
            Assert.True(actual > expected);
        }
        public void Should_Return_Single_Rountrip_Flight()
        {
            //Arrange
            var expected = "1746"; //Flight Number

            var flightSearchModel = new FlightSearchModel
            {
                TripType        = "RT",
                Origin          = "LGA",
                Destination     = "ATL",
                DepartureDate   = "2/9/2019",
                ReturnDate      = "2/9/2019",
                TotalPassengers = 1
            };

            //Act
            var actual = _repository.GetFlights(flightSearchModel).DepartingFlights.FirstOrDefault().FlightNumber;


            //Assert
            Assert.AreEqual(expected, actual);
        }
        public async Task <IActionResult> Index()
        {
            var searchModel = new FlightSearchModel
            {
                Adult          = 1,
                Child          = 2,
                Infant         = 3,
                Origins        = new[] { "THR" },
                Destinations   = new[] { "ISF" },
                DepartureDates = new[] { DateTime.Now.AddDays(29) }
            };

            var existed = await _flightCacheManager.GetExpirationAsync(searchModel, 1);

            var result = await _flightCacheManager.SearchFromCacheAsync(searchModel, 1, async() =>
            {
                return(new FlightSearchResult());
            });

            var cacheDetail = new CacheDetail
            {
                CurrentRPM             = await _flightCacheManager.GetRpmAsync(searchModel, 1),
                CalculatedCacheMinutes = await _flightCacheManager.CalculateCacheMinutesAsync(searchModel, 1),
                ExistedCacheMinutes    = existed,
            };

            _cacheDetails.Insert(0, cacheDetail);

            var viewModel = new IndexViewModel
            {
                FlightSearchResult = result,
                CacheDetails       = _cacheDetails
            };

            return(View(viewModel));
        }
Beispiel #11
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));
        }
Beispiel #12
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));
        }