Exemplo n.º 1
0
        //Search flight by date
        public ActionResult GetFlightsByDate()
        {
            FlightsVM flightsVM = new FlightsVM();

            flightsVM.FlightsByFilter = _flightsService.GetAllFlightsAsync().Result;
            return(View(flightsVM));
        }
Exemplo n.º 2
0
        public ActionResult GetFlightsByCity(string cityDep)
        {
            FlightsVM flightsVM = new FlightsVM();

            flightsVM.FlightsByFilter = _flightsService.GetFlightsByCityOfDepartureAsync(cityDep).Result;
            return(PartialView("_TableOfFilteredFlights", flightsVM.FlightsByFilter));
        }
Exemplo n.º 3
0
        public ActionResult GetFlightByNumber(string number, DateTime date)
        {
            FlightsVM flightsVM = new FlightsVM();

            flightsVM.FlightsByFilter = _flightsService.GetFlightsByNumberAsync(number, date).Result;
            return(PartialView("_TableOfFilteredFlights", flightsVM.FlightsByFilter));
        }
Exemplo n.º 4
0
        public ActionResult GetFlightsByDate(DateTime dateOfDep)
        {
            FlightsVM flightsVM = new FlightsVM
            {
                FlightsByFilter = _flightsService.GetFlightsByDateOfDepartureAsync(dateOfDep).Result
            };

            return(PartialView("_TableOfFilteredFlights", flightsVM.FlightsByFilter));
        }
Exemplo n.º 5
0
        public PartialViewResult _GetFlightsByCityDA(string city, string city1)
        {
            FlightsVM flightsVM = new FlightsVM();

            flightsVM.FlightsByFilter = _flightsService.GetFlightByCityOfDepadtureAndArrivalAsync(city, city1).Result;
            flightsVM.Cities          = _flightsService.GetCities();

            return(PartialView("_TableOfFilteredFlights", flightsVM.FlightsByFilter));
        }
Exemplo n.º 6
0
        public ActionResult Index()
        {
            FlightsVM flightsVM = new FlightsVM();

            flightsVM.FlightsByFilter = _flightsService.GetAllFlightsAsync().Result;
            flightsVM.Cities          = _flightsService.GetCities();

            return(PartialView(flightsVM));
        }
Exemplo n.º 7
0
        //Search flight by city of departure
        public ActionResult GetFlightsByCity()
        {
            FlightsVM flightsVM = new FlightsVM();

            flightsVM.Cities          = _flightsService.GetCities();
            flightsVM.FlightsByFilter = _flightsService.GetAllFlightsAsync().Result;
            return(View(flightsVM));

            //var model = _flightsService.GetAllFlightsAsync().Result;

            //return View(model);
        }
Exemplo n.º 8
0
        public async Task <ActionResult> SearchFlights(string origin, string destination, string departureDate, string returnDate, string adults, string currency)
        {
            FlightsVM viewModel = new FlightsVM();

            try
            {
                viewModel = await _flightService.SearchFlightsAsync(origin, destination, departureDate, returnDate, adults, currency);
            }
            catch (Exception ex)
            {
            }
            return(PartialView("_FlightsList", viewModel));
        }
Exemplo n.º 9
0
        public static FlightsVM MapToViewModel(this ErrorFromJson model)
        {
            if (model == null)
            {
                return(null);
            }

            FlightsVM flightsVM = new FlightsVM();

            foreach (var error in model.Errors)
            {
                flightsVM.ErrorMessages.Add(error.Detail + error.Source.Parameter);
            }

            return(flightsVM);
        }
Exemplo n.º 10
0
        private FlightsVM CheckIfFlightsExistInDatabase(string origin, string destination, string departureDate, string returnDate, string adults, string currency)
        {
            FlightsVM flightsVm = new FlightsVM();

            var existingFlights = _unitOfWork.Flights.GetAllAsQueryableAsNoTracking().ToList();

            if (existingFlights != null || existingFlights.Count() != 0)
            {
                var flightsForView = existingFlights.Where(f => f.NumberOfPassangers == Convert.ToInt32(adults) &&
                                                           f.OriginAirportIATA == origin &&
                                                           f.DestinationAirportIATA == destination &&
                                                           f.OriginDepartureTime.ToString("MM/dd/yyyy").Equals(departureDate) &&
                                                           f.OriginArrivalTime.ToString("MM/dd/yyyy").Equals(returnDate) &&
                                                           f.Currency == currency
                                                           ).ToList();

                flightsVm.Flights = flightsForView.MapListToViewModel();
            }

            return(flightsVm);
        }
Exemplo n.º 11
0
        private async Task SaveFlightsToDb(FlightsVM viewModel)
        {
            try
            {
                var existingFlights = _unitOfWork.Flights.GetAllAsQueryable().ToList();
                var flightsToSave   = viewModel.Flights;

                var flightsNotToSave = flightsToSave
                                       .Where(f => existingFlights.Select(fl => fl.NumberOfPassangers).Contains(f.NumberOfPassangers)

                                              && existingFlights.Select(fl => fl.OriginAirportIATA).Contains(f.OriginDepartureAirport) &&
                                              existingFlights.Select(fl => fl.DestinationAirportIATA).Contains(f.DestinationArrivalAirport)

                                              && existingFlights.Select(fl => fl.DestinationAirportIATA).Contains(f.DestinationDepartureAirport) &&
                                              existingFlights.Select(fl => fl.OriginAirportIATA).Contains(f.OriginArrivalAirport)

                                              && existingFlights.Select(fl => fl.OriginArrivalLayovers).Contains(f.OriginArrivalLayovers) &&
                                              existingFlights.Select(fl => fl.DestinationArrivalLayovers).Contains(f.DestinationArrivalLayovers)

                                              && existingFlights.Select(fl => fl.TotalPrice).Contains(f.TotalPrice) &&
                                              existingFlights.Select(fl => fl.Currency).Contains(f.Currency)
                                              ).ToList();

                var flightsToDbSave = flightsToSave.Except(flightsNotToSave).ToList();


                if (viewModel.Flights != null && viewModel.Flights.Count != 0)
                {
                    var flightsDbModels = viewModel.Flights.MapListToModel();
                    _unitOfWork.Flights.AddRangeToDatabase(flightsDbModels);

                    await _unitOfWork.SaveChangesAsync();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Exemplo n.º 12
0
        public async Task <FlightsVM> SearchFlightsAsync(string origin, string destination, string departureDate, string returnDate, string adults, string currency)
        {
            FlightsVM viewModel = new FlightsVM();

            try
            {
                viewModel = CheckIfFlightsExistInDatabase(origin, destination, departureDate, returnDate, adults, currency);
                if (viewModel.Flights.Count() != 0)
                {
                    return(viewModel);
                }

                var bearerToken = await RequestBearerTokenAsync();

                var responseJson = await RequestFlightsDataAsync(bearerToken, origin, destination, departureDate, returnDate, adults, currency);

                if (responseJson.Contains(Errors))
                {
                    var errorJsonModel = JsonConvert.DeserializeObject <ErrorFromJson>(responseJson);
                    viewModel = errorJsonModel.MapToViewModel();
                }
                else
                {
                    var lowFareFlightsJsonModel = JsonConvert.DeserializeObject <LowFareFlightsJson>(responseJson);
                    viewModel = lowFareFlightsJsonModel.MapToViewModel(adults);

                    await SaveFlightsToDb(viewModel);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(viewModel);
        }
Exemplo n.º 13
0
 public AddFlightsForm()
 {
     InitializeComponent();
     DataContext = new FlightsVM();
 }
Exemplo n.º 14
0
        public static FlightsVM MapToViewModel(this LowFareFlightsJson model, string adults)
        {
            if (model == null)
            {
                return(null);
            }

            FlightsVM flightsVM = new FlightsVM();

            foreach (var flightOffer in model.Data)
            {
                FlightVM flightVM = new FlightVM();

                if (model.Meta.Defaults.Adults == 0)
                {
                    flightVM.NumberOfPassangers = Convert.ToInt32(adults);
                }
                else
                {
                    flightVM.NumberOfPassangers = model.Meta.Defaults.Adults;
                }

                foreach (var offerItem in flightOffer.OfferItems)
                {
                    var totalPrice = offerItem.Price.Total;
                    flightVM.TotalPrice = totalPrice;
                    flightVM.Currency   = model.Meta.Currency;

                    var services = offerItem.Services;

                    // Origin segment
                    var originSegment          = services.First();
                    var numberOfOriginLayovers = originSegment.Segments.Count() - 1;
                    flightVM.DestinationArrivalLayovers = numberOfOriginLayovers;

                    var originDepartureAirport = originSegment.Segments.First().FlightSegment.Departure.IataCode;
                    flightVM.OriginDepartureAirport = originDepartureAirport;

                    var originDepartureTime = originSegment.Segments.First().FlightSegment.Departure.TimeAt;
                    flightVM.OriginDepartureTime = Convert.ToDateTime(originDepartureTime);

                    var destinationArrivalAirport = originSegment.Segments.Last().FlightSegment.Arrival.IataCode;
                    flightVM.DestinationArrivalAirport = destinationArrivalAirport;

                    var destinationArrivalTime = originSegment.Segments.Last().FlightSegment.Arrival.TimeAt;
                    flightVM.DestinationArrivalTime = Convert.ToDateTime(destinationArrivalTime);

                    var returnSegment = services.Last();
                    var numberOfOriginReturnLayovers = returnSegment.Segments.Count() - 1;
                    flightVM.OriginArrivalLayovers = numberOfOriginReturnLayovers;

                    var destinationReturnDepartureAirport = returnSegment.Segments.First().FlightSegment.Departure.IataCode;
                    flightVM.DestinationDepartureAirport = destinationReturnDepartureAirport;

                    var destinationReturnDepartureTime = returnSegment.Segments.First().FlightSegment.Departure.TimeAt;
                    flightVM.DestinationDepartureTime = Convert.ToDateTime(destinationReturnDepartureTime);

                    var originReturnArrivalAirport = returnSegment.Segments.Last().FlightSegment.Arrival.IataCode;
                    flightVM.OriginArrivalAirport = originReturnArrivalAirport;

                    var originReturnArrivalTime = returnSegment.Segments.Last().FlightSegment.Arrival.TimeAt;
                    flightVM.OriginArrivalTime = Convert.ToDateTime(originReturnArrivalTime);

                    flightsVM.Flights.Add(flightVM);
                }
            }

            return(flightsVM);
        }