private Vehicle createVehicle(CreatingVehicles.eTypeOfVehicles i_TypeOfVehicle) { CreatingVehicles vehiclesMaker = new CreatingVehicles(i_TypeOfVehicle); Vehicle vehicleToAdd = vehiclesMaker.CreateVehicle(); StringBuilder askForData = vehicleToAdd.AskForData; string[] splitAskForData = askForData.ToString().Split('\n'); List <int> enumable = getEnumableProperties(splitAskForData[splitAskForData.Length - 2]); string[] storeData = new string[splitAskForData.Length - 2]; for (int i = 0; i < storeData.Length; i++) { if (enumable.Contains(i)) { Type getType = getVehicleTypeOfEnum(i_TypeOfVehicle); PrintingUtils.PrintListOfEnum(splitAskForData[i], getType); storeData[i] = Console.ReadLine(); } else { Console.WriteLine(splitAskForData[i]); storeData[i] = Console.ReadLine(); } } vehicleToAdd.SetVehicleData = storeData; return(vehicleToAdd); }
private void getFuelToAdd(out FuelVehicle.eFuelType o_FuelType, out float o_FuelToAdd) { PrintingUtils.PrintListOfEnum("Please write below the fuel type:", typeof(FuelVehicle.eFuelType)); bool isValid = Enum.TryParse(Console.ReadLine(), out o_FuelType) && Enum.IsDefined(typeof(FuelVehicle.eFuelType), o_FuelType); if (isValid == false) { throw new FormatException("Fail parsing fuel type"); } Console.WriteLine("Please insert the amount of fuel you would like to add: "); bool isParse = float.TryParse(Console.ReadLine(), out o_FuelToAdd); if (isParse == false) { throw new FormatException("Fail parsing the amount of fuel to add"); } }
private void addVehicle() { Console.WriteLine("Creating Vehicle: "); Console.WriteLine("Please write your name: "); string ownerName = Console.ReadLine(); Console.WriteLine("Please write your phone number: "); string ownerPhone = Console.ReadLine(); bool isValid = false; do { bool isValidPhoneNumber = int.TryParse(ownerPhone, out int intPhoneNumber); if (isValidPhoneNumber == false) { Console.WriteLine("Fail to add the phone number you entered."); Console.WriteLine("Please write your phone number: "); ownerPhone = Console.ReadLine(); continue; } PrintingUtils.PrintListOfEnum("Please choose a vehicle", typeof(CreatingVehicles.eTypeOfVehicles)); string option = Console.ReadLine(); isValid = Enum.TryParse(option, true, out CreatingVehicles.eTypeOfVehicles result) && Enum.IsDefined(typeof(CreatingVehicles.eTypeOfVehicles), result); if (isValid) { Vehicle vehicle = createVehicle(result); AutoRepairShop.VehicleInShop toAdd = new AutoRepairShop.VehicleInShop( ownerName, ownerPhone, vehicle); r_AutoRepairShop.AddVehicleToStore(toAdd, out bool isAdded); PrintingUtils.VehicleAdded(toAdd.VehicleLicenseNumber, isAdded); break; } Console.WriteLine("please choose a valid option."); }while (isValid == false); }
private AutoRepairShop.VehicleInShop.eVehicleStatus?getStatus() { AutoRepairShop.VehicleInShop.eVehicleStatus?returnStatus; PrintingUtils.PrintListOfEnum( "Please write below the vehicle status:", typeof(AutoRepairShop.VehicleInShop.eVehicleStatus)); string status = Console.ReadLine(); bool isValid = Enum.TryParse(status, out AutoRepairShop.VehicleInShop.eVehicleStatus result) && Enum.IsDefined(typeof(AutoRepairShop.VehicleInShop.eVehicleStatus), result); if (isValid) { returnStatus = result; } else { string errorMessage = "You have to choose from the following options"; ValueOutOfRangeException ex = new ValueOutOfRangeException(1, 3, errorMessage); throw new FormatException("Fail parsing the vehicle status", ex); } return(returnStatus); }