Ejemplo n.º 1
0
        private VehicleDetails makeNewVehicle(string i_LicensePlate)
        {
            bool           newVehicleWasMade = false;
            VehicleDetails newVehicle        = new VehicleDetails();

            do
            {
                try
                {
                    chooseVehicleType(out string vehicleType);
                    newVehicle.Vehicle = VehicleMaker.MakeNewVehicle(i_LicensePlate, vehicleType);
                    newVehicleWasMade  = true;
                }
                catch (FormatException fe)
                {
                    Console.WriteLine(fe.Message);
                }
                catch (ValueOutOfRangeException ve)
                {
                    Console.WriteLine(string.Format("{0}, Please insert value between {1} - {2}", ve.ToString(), ve.MinValue, ve.MaxValue));
                }
            }while(newVehicleWasMade == false);

            return(newVehicle);
        }
        /// <summary>
        /// “Insert” a new vehicle into the garage. The user will be asked to
        /// select a vehicle type out of the supported vehicle types, and to
        /// input the license number of the vehicle.If the vehicle is already
        /// in the garage(based on license number) the system will display an
        /// appropriate message and will use the vehicle in the garage
        /// (and will change the vehicle status to “In Repair”), if not, a new
        /// object of that vehicle type will be created and the user will be
        /// prompted to input the values for the properties of his vehicle,
        /// according to the type of vehicle he wishes to add.
        /// </summary>
        private void insertVehicleToGarage()
        {
            string licenseNumber = GetLicenseNumber();
            string ownerName;
            string ownerPhone;

            if (Garage.VehicleIsAlreadyInTheGarage(licenseNumber))
            {
                Console.WriteLine(string.Format(DisplayVehicleIsAlreadyInTheGarage(licenseNumber)));
                Garage.LicenseNumbersList.TryGetValue(licenseNumber, out VehicleDetails value);
                value.VehicleStatus = eVehicleStatus.InRepair;
            }
            else
            {
                ownerName  = GetOwnerName();
                ownerPhone = GetOwnerPhoneNumber();
                eVehicleType vehicleType = (eVehicleType)Enum.Parse(typeof(eVehicleType), GetVehicleType());
                VehicleMaker.MakeNewVehicle(vehicleType, out Vehicle vehicle);
                setVehicle(vehicle, licenseNumber);
                Garage.Insert(vehicle, licenseNumber, ownerName, ownerPhone);
            }
        }