Example #1
0
        private async Task Confirm(object o)
        {
            if (!ValidateConfirm())
            {
                return;
            }

            DateTime scheduledDeparture = SelectedDate.AddHours(DepartureTimeHours.Value).AddMinutes(DepartureTimeMinutes.Value);

            UiState = UiState.Wait;

            await m_crudManager.AddFlight(SelectedRouteAircraft.RouteAircraftId, FlightNumber, scheduledDeparture);

            UiState = UiState.Normal;

            MessageBoxResult result = MessageBox.Show("Flight added successfully. Add another?", "Success", MessageBoxButton.YesNo);

            if (result == MessageBoxResult.Yes)
            {
                m_pageController.AddFlight();
            }
            else
            {
                m_pageController.Home();
            }
        }
Example #2
0
        public void AddFlightTest()
        {
            using (FlightReservationContext db = new FlightReservationContext())
            {
                List <ClassPricingScheme> pricingScheme = new List <ClassPricingScheme>
                {
                    new ClassPricingScheme {
                        TravelClassCode = "E", TravelClassName = "Economy Class", AdultFare = 200, ChildFare = 160, InfantFare = 40
                    },
                    new ClassPricingScheme {
                        TravelClassCode = "B", TravelClassName = "Business Class", AdultFare = 1000, ChildFare = 800, InfantFare = 200
                    }
                };

                Route newRoute = new Route
                {
                    AirlineCode            = "BA",
                    OriginAirportCode      = "BHX",
                    DestinationAirportCode = "ARN",
                    PricingScheme          = JsonConvert.SerializeObject(pricingScheme)
                };

                db.Route.Add(newRoute);
                db.SaveChanges();

                RouteAircraft newRouteAircraft = new RouteAircraft
                {
                    RouteId        = newRoute.RouteId,
                    IcaoTypeCode   = "A320",
                    FlightDuration = 105
                };

                db.RouteAircraft.Add(newRouteAircraft);
                db.SaveChanges();

                m_crudManager.AddFlight(newRouteAircraft.RouteAircraftId, "BA188", new DateTime(2020, 9, 6, 15, 30, 0));

                var query =
                    from f in db.Flight
                    join ra in db.RouteAircraft on f.RouteAircraftId equals ra.RouteAircraftId
                    join r in db.Route on ra.RouteId equals r.RouteId
                    where r.AirlineCode == "BA" &&
                    r.OriginAirportCode == "BHX" &&
                    r.DestinationAirportCode == "ARN"
                    select f;

                List <Flight> selectedFlights = query.ToList();

                Assert.IsTrue(selectedFlights.Exists(f => f.RouteAircraftId == newRouteAircraft.RouteAircraftId &&
                                                     f.FlightNumber == "BA188" && f.ScheduledDeparture == new DateTime(2020, 9, 6, 15, 30, 0)));

                Flight flightToDelete = selectedFlights.Find(f => f.RouteAircraftId == newRouteAircraft.RouteAircraftId &&
                                                             f.FlightNumber == "BA188" && f.ScheduledDeparture == new DateTime(2020, 9, 6, 15, 30, 0));

                if (flightToDelete != null)
                {
                    db.Flight.Remove(flightToDelete);
                }

                db.RouteAircraft.Remove(newRouteAircraft);
                db.Route.Remove(newRoute);

                db.SaveChanges();
            }
        }