public static Vehicle SetNewVehicle() { string vehicle = string.Empty; Dictionary <string, string> parametrs = new Dictionary <string, string>(); string currentWheelPressure = string.Empty; string currentEnergy = string.Empty; string licenseNumber = string.Empty; string typeOfWheel = string.Empty; string modelType = string.Empty; bool validationFlag = !true; System.Console.WriteLine("Hello! Please enter your vehicle type, those are the vehicle we support:"); int i = 0; foreach (eVehicleType type in Enum.GetValues(typeof(eVehicleType))) { System.Console.WriteLine("* For " + type.ToString() + " Press " + i); i++; } while (!validationFlag) { try { vehicle = System.Console.ReadLine(); validationFlag = Validation.TypeOfVehicle(vehicle); } catch (ArgumentException e) { validationFlag = false; System.Console.WriteLine(e.Message); } } validationFlag = !true; parametrs.Add("Vehicle Type", vehicle.ToString()); Enum.TryParse <eVehicleType>(vehicle, out eVehicleType eVehicle); VehicleCreation.AddSpecInfo(eVehicle, parametrs); System.Console.WriteLine("Please enter your number of license:"); while (!validationFlag) { try { licenseNumber = System.Console.ReadLine(); validationFlag = UIValidation.IsANumberValidation(licenseNumber); } catch (FormatException e) { validationFlag = false; System.Console.WriteLine(e.Message); } } validationFlag = !true; Console.Clear(); parametrs.Add("Licence Number", licenseNumber); System.Console.WriteLine("Please enter the current pressure in your wheele:"); while (!validationFlag) { try { parametrs.TryGetValue("Maximal Air Pressure", out string maxAirPressue); validationFlag = Validation.RangeValidation(currentWheelPressure = System.Console.ReadLine(), maxAirPressue); } catch (ArgumentException e) { validationFlag = !true; System.Console.WriteLine(e.Message); } } validationFlag = !true; parametrs.Add("Current Wheel Pressure", currentWheelPressure); System.Console.WriteLine("Please enter the type of the wheele:"); while (!validationFlag) { try { typeOfWheel = UIValidation.UserStringValidation(System.Console.ReadLine()); validationFlag = true; } catch (FormatException e) { validationFlag = !true; System.Console.WriteLine(e.Message); } } validationFlag = !true; parametrs.Add("Type Of Wheele", typeOfWheel); System.Console.WriteLine("Please enter your current amount of eneregy left (Whether it's an" + " electric or a fuel engine):"); while (!validationFlag) { try { parametrs.TryGetValue("Engine Capacity", out string engineCapacity); validationFlag = Validation.RangeValidation(currentEnergy = System.Console.ReadLine(), engineCapacity); } catch (ArgumentException e) { validationFlag = !true; System.Console.WriteLine(e.Message); } } validationFlag = !true; parametrs.Add("Amount Of Energy Left", currentEnergy); System.Console.WriteLine("Please enter the model of your car:"); while (!validationFlag) { try { modelType = UIValidation.UserStringValidation(System.Console.ReadLine()); validationFlag = true; } catch (FormatException e) { validationFlag = !true; System.Console.WriteLine(e.Message); } } parametrs.Add("Model Type", modelType); parametrs = expendVehicleParameter(eVehicle, parametrs); VehicleCreation vehicleBuilder = new VehicleCreation(parametrs, eVehicle); Vehicle newVehicle = vehicleBuilder.vehicle; return(newVehicle); }
// Adds a vehicle to the garage, if vehicle is already in the garage, sets status as maintenence internal void AddVehicle(GarageLogic.Garage i_Garage) { string vehicle = string.Empty; Dictionary <string, string> parametrs = new Dictionary <string, string>(); string licenseNumber = string.Empty; string typeOfWheels = string.Empty; string modelType = string.Empty; bool validationFlag = false; string name = string.Empty; string phoneNumber = string.Empty; Console.Clear(); // Gets license number, if already exists change status to maintenence Console.WriteLine("Enter License Number"); licenseNumber = Console.ReadLine(); try { i_Garage.IsNotInGarage(licenseNumber); } catch { i_Garage.ChangeCarStatus(licenseNumber, Garage.eCarStatus.Maintenence); Console.WriteLine("Vehicle already in garage, status changes to maintenence"); Thread.Sleep(1200); return; } Console.Clear(); // get customer inforamtion Console.WriteLine("Please write your name"); name = Console.ReadLine(); Console.WriteLine("Please write your phone number"); phoneNumber = Console.ReadLine(); Console.Clear(); // get and validate vehicle type System.Console.WriteLine("Please enter your vehicle type, those are the vehicle we support:"); int i = 0; foreach (VehicleCreation.eVehicleType typeOfCar in Enum.GetValues(typeof(VehicleCreation.eVehicleType))) { System.Console.WriteLine("* For " + typeOfCar.ToString() + " Press " + i); i++; } while (!validationFlag) { try { vehicle = System.Console.ReadLine(); validationFlag = Validation.TypeOfVehicle(vehicle); } catch (Exception e) { validationFlag = false; System.Console.WriteLine(e.Message); } } parametrs.Add("Licence Number", licenseNumber); parametrs.Add("Vehicle Type", vehicle.ToString()); Enum.TryParse <VehicleCreation.eVehicleType>(vehicle, out VehicleCreation.eVehicleType vehicleType); // get Vehicle Model Console.WriteLine("Please enter vehicle model"); modelType = Console.ReadLine(); parametrs.Add("Model Type", modelType); Console.Clear(); // get wheels information System.Console.WriteLine("please enter the type of your wheels"); typeOfWheels = Console.ReadLine(); parametrs.Add("Type Of Wheel", typeOfWheels); string maxAirPressure = string.Empty; System.Console.WriteLine("Please enter the max air of your wheels"); bool isNumber = false; while (!isNumber) { maxAirPressure = Console.ReadLine(); try { ValidtysUI.CheckIfANumber(maxAirPressure); isNumber = true; } catch (FormatException e) { Console.WriteLine(e.Message); } } isNumber = false; parametrs.Add("Maximal Air Pressure", maxAirPressure); string currentAirPressure = string.Empty; System.Console.WriteLine("Please enter the current air of your wheels"); bool isVaildAir = false; while (!isVaildAir) { currentAirPressure = Console.ReadLine(); try { ValidtysUI.CheckInputValidity(currentAirPressure, maxAirPressure); isVaildAir = true; } catch (ArgumentException e) { Console.WriteLine(e.Message); } catch (FormatException e) { Console.WriteLine(e.Message); } } parametrs.Add("Current Wheel Pressure", currentAirPressure); Console.Clear(); // get engine information string maximumEnergy = string.Empty; bool isValid = false; Console.WriteLine("Please enter the maximun energy of your vehicle"); while (!isNumber) { maximumEnergy = Console.ReadLine(); try { ValidtysUI.CheckIfANumber(maximumEnergy); isNumber = true; } catch (FormatException e) { Console.WriteLine(e.Message); } } parametrs.Add("Max energy", maximumEnergy); string energyLeft = string.Empty; Console.WriteLine("Please enter the enregy left in the vehicle"); while (!isValid) { energyLeft = Console.ReadLine(); try { ValidtysUI.CheckInputValidity(energyLeft, maximumEnergy); isValid = true; } catch (ArgumentException e) { Console.WriteLine(e.Message); } catch (FormatException e) { Console.WriteLine(e.Message); } } parametrs.Add("Amount Of Energy Left", energyLeft); Console.WriteLine("Is the vehicle electric?"); Console.WriteLine("1. yes"); Console.WriteLine("2. no"); string answer = Console.ReadLine(); Engine.eEngineType type = Engine.eEngineType.Electric; bool isOneOrTwo = false; while (!isOneOrTwo) { if (answer == "1") { type = Engine.eEngineType.Electric; isOneOrTwo = true; } if (answer == "2") { type = Engine.eEngineType.Fuel; int numberOfChoice = 1; Console.WriteLine("Please pick one of the Fuel types below: "); // iterate through gas types available and prints them foreach (GarageLogic.FuelEngine.eFuelType fuelType in Enum.GetValues(typeof(GarageLogic.FuelEngine.eFuelType))) { Console.WriteLine(numberOfChoice + ". " + fuelType.ToString()); numberOfChoice++; } bool isFuelType = false; string chosenFuelType = string.Empty; while (!isFuelType) { chosenFuelType = Console.ReadLine(); try { ValidtysUI.CheckFuelType(chosenFuelType); Array enumValues = Enum.GetValues(typeof(FuelEngine.eFuelType)); int chosenAsInt = int.Parse(chosenFuelType) - 1; parametrs.Add("Fuel Kind", enumValues.GetValue(chosenAsInt).ToString()); isFuelType = true; } catch (ArgumentException e) { Console.WriteLine(e.Message); } catch (FormatException e) { Console.WriteLine(e.Message); } } isOneOrTwo = true; } if (answer != "1" && answer != "2") { Console.WriteLine("please enter 1 or 2"); answer = Console.ReadLine(); } } parametrs.Add("Engine Type", type.ToString()); Console.Clear(); ExpendVehicleParameter(vehicleType, parametrs); VehicleCreation BuildVehicle = new VehicleCreation(parametrs, vehicleType); Vehicle newVehicle = BuildVehicle.Vehicle; i_Garage.AddCustomer(name, phoneNumber, newVehicle); // show success message and takes back to main menu SuccessFinishOperation(); }