示例#1
0
        public void AddAirport()
        {
            commandLine.Write("Add new Airport.");
            commandLine.Write("Enter City:");
            string city = commandLine.Read();

            while (AnalyzeString(city) == null)
            {
                city = commandLine.Read();
            }

            commandLine.Write("Enter Country:");
            string country = commandLine.Read();

            while (AnalyzeString(country) == null)
            {
                country = commandLine.Read();
            }

            commandLine.Write("Enter Name:");
            string name = ReadAirportName();

            while (AnalyzeString(name) == null)
            {
                name = commandLine.Read();
            }

            commandLine.Write("Enter Code:");
            string code = ReadAirportCode();

            while (AnalyzeString(code) == null)
            {
                code = commandLine.Read();
            }

            int freeGates = commandLine.ReadInt("Enter number of free gates:");

            Airport airport = new Airport(code, name, city, country, freeGates);

            airportStore.AddAirport(airport);
            commandLine.Write($"Successfully added airport: {airport}");
        }
示例#2
0
        private AircraftModel GetAircraftModel()
        {
            int           id;
            AircraftModel aircraftModel = null;

            while (aircraftModel == null)
            {
                id            = commandLine.ReadInt("Enter aircraft model id:");
                aircraftModel = aircraftModelManager.GetAircraftModel(id);
            }

            return(aircraftModel);
        }
示例#3
0
        public void AddModel()
        {
            commandLine.Write("Add new aircraft model.");
            commandLine.Write("Enter Make:");
            string make = commandLine.Read();

            commandLine.Write("Enter Model:");
            string        model         = commandLine.Read();
            int           speed         = commandLine.ReadInt("Enter Model speed in km/h. (Average speed is 828 km/h):");
            int           numberOfSeats = commandLine.ReadInt("Enter Number of seats:");
            AircraftModel aircraftModel = new AircraftModel(make, model, speed, numberOfSeats);

            store.AddModel(aircraftModel);
            commandLine.Write($"Successfully added model: {aircraftModel}");
        }
示例#4
0
        public void EditFlight()
        {
            commandLine.Write("Edit flight.");
            int    id     = commandLine.ReadInt("Enter flight number:");
            Flight flight = flightStore.GetFlight(id);

            if (flight.Id == 0)
            {
                commandLine.Write($"Flight with number {flight.Id} was not found.");
                return;
            }

            commandLine.Write("Enter departure airport code:");
            flight.DepartureAirportCode = ReadDepartureAirportCode();
            commandLine.Write("Enter departure date:");
            flight.DepartureDateTime = ReadDate();
            commandLine.Write("Enter destination airport:");
            flight.ArrivalAirportCode = ReadArrivalAirportCode(flight.DepartureAirportCode);
            commandLine.Write("Enter departure gate.");
            flight.GateDeparture = GetGate(flight.DepartureAirportCode);

            if (flight.GateDeparture == 0)
            {
                commandLine.Write($"Gates in airport with code {flight.DepartureAirportCode} are not available.");
                return;
            }

            airportManager.AddOrRemoveOneGate("add", flight.DepartureAirportCode);
            commandLine.Write("Add airplane:");

            do
            {
                flight.Plane = airplaneManager.GetAirplane();
                if (flight.Plane == null)
                {
                    commandLine.Write("Airplane doesn't exist. Add another airplane:");
                }
            }while (flight.Plane == null);

            commandLine.Write("Enter date when flight arrived to the airport:");
            flight.ArrivedToAirport = ReadDate();

            if (flight.DepartureDateTime - flight.ArrivedToAirport < flight.Plane.MaintenanceTime)
            {
                commandLine.Write("Flight is not available. Plane is not ready yet.");
                return;
            }

            TimeSpan durationOfFlight = CalculateFlightDuration(flight.DepartureAirportCode, flight.ArrivalAirportCode, flight.Plane.Model.Speed);

            flight.ArrivalDateTime = CalculateArrivalDate(flight.DepartureDateTime, durationOfFlight);
            commandLine.Write("Enter arrival gate.");
            flight.GateArrival = GetGate(flight.ArrivalAirportCode);

            if (flight.GateArrival == 0)
            {
                commandLine.Write($"Gates in airport with code {flight.ArrivalAirportCode} are not available.");
                return;
            }

            airportManager.AddOrRemoveOneGate("delete", flight.ArrivalAirportCode);
            flight.NumberOfAvailableTickets = flight.Plane.Model.NumberOfSeats;
            flight.Plane.AirportCode        = flight.ArrivalAirportCode;

            flightStore.UpdateFlight(flight);
            commandLine.Write($"Successfully updated flight {flight}");
        }