Пример #1
0
 public FlightView()
 {
     this.InitializeComponent();
     ViewModel = new FlightVM();
     ListContainer.ItemsSource = ViewModel.Flights;
     this.Loaded += OnLoaded;
 }
Пример #2
0
        public JsonResult Schedule(FlightVM flightInfo)
        {
            string   origin      = flightInfo.Origin_1;
            string   destination = flightInfo.Destination_1;
            DateTime departTime  = DateTime.Parse(flightInfo.FromDate_1);

            var scheduleList = db.Schedules
                               .Where(x => x.Origin == origin && x.Destination == destination &&
                                      DbFunctions.TruncateTime(x.DepartTime) == departTime.Date);

            var result = new List <ScheduleVM>();

            foreach (var schedule in scheduleList)
            {
                var seatList = schedule.Flight.Seats;
                foreach (var seat in seatList)
                {
                    var item = new ScheduleVM();
                    item.FlightNo    = schedule.FlightID;
                    item.Origin      = schedule.Origin;
                    item.Destination = schedule.Destination;
                    item.SeatNo      = seat.SeatID;
                    item.ScheduleID  = schedule.ID;
                    item.DepartTime  = schedule.DepartTime.ToString("yyyy-MM-dd HH:mm");
                    if (!IsSeatReserved(item))
                    {
                        result.Add(item);
                    }
                }
            }

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public void Post(FlightVM flight)
        {
            var _flight = new Flight {
                Id = flight.Id, PlaneName = flight.PlaneName, Seats = flight.Seats, Route = flight.Route
            };

            _manager.AddFlight(_flight);
        }
Пример #4
0
        public async Task <IActionResult> PostAsync(FlightVM flight)
        {
            var _flight = new Flight {
                Id = flight.Id, PlaneName = flight.PlaneName, Seats = flight.Seats, Route = flight.Route
            };

            await _flightRepository.CreateAsync(_flight);

            return(Ok());
        }
Пример #5
0
        //Return flight info and Purchase Price
        public async Task <IActionResult> Book(int flightId)
        {
            HttpContext.Session.SetInt32("CurrentFlight", flightId);
            Flight flight = await ApiClientFactory.Instance.GetFlight(flightId);

            FlightVM flightVM = new FlightVM();

            flightVM.FlightID      = flight.FlightID;
            flightVM.Departure     = flight.Departure;
            flightVM.Destination   = flight.Destination;
            flightVM.Date          = flight.Date;
            flightVM.PurchasePrice = await ApiClientFactory.Instance.CalculatePrice(flightId);

            HttpContext.Session.SetInt32("CurrentPurchasePrice", Convert.ToInt32(flightVM.PurchasePrice));
            return(View(flightVM));
        }
Пример #6
0
        public async Task <IActionResult> CreateFlight([FromForm] FlightVM model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;


                if (model.Photo != null)
                {
                    string   uploadsFolder = Path.Combine(hostingEnvironment.WebRootPath, "images");
                    string[] splitwords    = model.Photo.FileName.Split("\\");
                    uniqueFileName = splitwords[splitwords.Count() - 1];
                    string filePath = Path.Combine(uploadsFolder, uniqueFileName);

                    model.Photo.CopyTo(new FileStream(filePath, FileMode.Create));
                }

                Flight newFlight = new Flight
                {
                    Id        = model.Id,
                    PlaneName = model.PlaneName,

                    Seats     = model.Seats,
                    Price     = model.Price,
                    Route     = model.Route,
                    Departure = model.Departure,
                    Arrive    = model.Arrive,

                    // Store the file name in PhotoPath property of the flight object
                    // which gets saved to the Flight database table
                    PhotoPath = uniqueFileName
                };

                await _flightRepository.CreateAsync(newFlight);

                return(RedirectToAction("AdminFlightView", "flight"));
            }
            return(View());
        }
Пример #7
0
        public static Flight MapToModel(this FlightVM viewModel, Flight model = null)
        {
            if (viewModel == null)
            {
                return(null);
            }

            if (model == null)
            {
                model = new Flight {
                    Id = Guid.NewGuid()
                }
            }
            ;

            // fields
            model.NumberOfPassangers = viewModel.NumberOfPassangers;

            model.OriginAirportIATA      = viewModel.OriginDepartureAirport;
            model.DestinationAirportIATA = viewModel.DestinationArrivalAirport;

            model.OriginDepartureTime    = viewModel.OriginDepartureTime;
            model.DestinationArrivalTime = viewModel.DestinationArrivalTime;

            model.DestinationDepartureTime = viewModel.DestinationDepartureTime;
            model.OriginArrivalTime        = viewModel.OriginArrivalTime;

            model.OriginArrivalLayovers      = viewModel.OriginArrivalLayovers;
            model.DestinationArrivalLayovers = viewModel.DestinationArrivalLayovers;

            model.TotalPrice = viewModel.TotalPrice;
            model.Currency   = viewModel.Currency;

            // relations

            return(model);
        }
Пример #8
0
        public JsonResult GetFlightsCoordinate()
        {
            /*Problem with subscribe
             * var end = (DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds;
             * var start = end - 3600;
             *
             * AirlineFlightSchedules date = new AirlineFlightSchedules()
             * {
             *  start_date = Convert.ToInt32(start),
             *  end_date = Convert.ToInt32(end)
             * };
             *
             * AirlineFlightSchedulesResult flights = _flightAwareAPI.GetAirlineFlightSchedules(date);
             */

            FlightVM            flightVM   = new FlightVM();
            List <FlightInfoVM> flightInfo = new List <FlightInfoVM>();

            TrackStruct            track      = new TrackStruct();
            FlightInfoStatusStruct infoStatus = new FlightInfoStatusStruct();

            List <string> list = new List <string>();

            list.Add("AUI146-1512800764-airline-0169");    //Ukraine: AUI146-1512800764-airline-0169
            list.Add("SIA321-1512973541-airline-0029");    //London SIA321-1512973541-airline-0029

            for (int i = 0; i < list.Count; i++)
            {
                FlightInfoVM flight = new FlightInfoVM();

                var coordinates = _flightAwareAPI.GetFlightTrack(new GetFlightTrack
                {
                    ident = list[i],
                    include_position_estimates = false
                });

                var info = _flightAwareAPI.GetFlightInfoStatus(new FlightInfoStatus
                {
                    ident           = list[i],
                    include_ex_data = false,
                    howMany         = 3
                });

                if (coordinates != null && info != null)
                {
                    track            = coordinates.tracks.ToList().Last();
                    flight.Latitude  = track.latitude;
                    flight.Longitude = track.longitude;

                    infoStatus      = info.flights.ToList().Last();
                    flight.FlightId = infoStatus.faFlightID;
                    flight.Airline  = infoStatus.airline.ToString();

                    flightInfo.Add(flight);
                }
            }

            flightVM.FlightInfoVM = flightInfo;

            try
            {
                var email = HttpContext.Request.Cookies["user_login"].Value;
                flightVM.Email = email;
            }
            catch (Exception e)
            {
                flightVM.Email = "Error";
            }

            return(Json(flightVM, JsonRequestBehavior.AllowGet));
        }
Пример #9
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);
        }