Exemple #1
0
        public void AddNewVehicleToGarage(GarageObjectGenerator i_VehicleGenerator, Garage i_TheGarage)
        {
            bool     newCustomerCreated = false;
            Customer newCustomer        = null;

            while (!newCustomerCreated)
            {
                Console.WriteLine("Hello and welcome to The Garage! {0}Please enter your name: (and press 'Enter')", Environment.NewLine);
                string name = Console.ReadLine();
                Console.WriteLine("Please enter your phone number: (10 digits and press 'Enter')");
                string phoneNumber = Console.ReadLine();

                try
                {
                    newCustomer        = new Customer(name, phoneNumber);
                    newCustomerCreated = true;
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.Message);
                }
            }

            List <string> informationDemandsForVehicle = null;

            int chosenVehicleToAdd = getVehicleNumberToGenerate(i_VehicleGenerator);

            string licenseNumber = getLicensePlateNumber();

            Vehicle vehicleToAddToGarage =
                i_VehicleGenerator.GenerateNewVehicle(chosenVehicleToAdd, licenseNumber, out informationDemandsForVehicle);

            newCustomer.Vehicle = vehicleToAddToGarage;

            do
            {
                List <string> answersListFromUser = getDetailsFromUser(informationDemandsForVehicle);

                i_VehicleGenerator.VehiclesSetter(informationDemandsForVehicle, answersListFromUser, vehicleToAddToGarage);
            }while (informationDemandsForVehicle.Count != 0); // continue from here

            string msgForUser;

            try
            {
                i_TheGarage.EnterNewVehicle(newCustomer, out msgForUser);
                if (msgForUser == null)
                {
                    Console.WriteLine("vehicle entered succesfully to the garage!");
                }
                else
                {
                    Console.WriteLine(msgForUser);
                }
            }
            catch (Exception valueExcepion)
            {
                Console.WriteLine(valueExcepion.Message);
                Console.WriteLine("could not enter your vehicle, the garage can not handle it");
            }
        }