public bool TakeOutVehicle(Garage <Vehicle> garage, string regNumber) { try { var vehicle = garage.Where(v => v.RegisteringNumber == regNumber.ToLower() || v.RegisteringNumber == regNumber.ToUpper()).First(); return(garageHandler.RemoveVehicle(garage, vehicle)); } catch (Exception) { return(false); } }
public Vehicle FindByRegNumber(Garage <Vehicle> garage, string regNumber) { try { var vehicle = garage.Where(v => v.RegisteringNumber == regNumber.ToLower() || v.RegisteringNumber == regNumber.ToUpper()).First(); return(vehicle); } catch (Exception) { return(null); } }
public void FindByProperties() { Console.Clear(); if (garage.Count > 0) { List <Vehicle> result = new List <Vehicle>(); int noOfWheel; bool success; Console.WriteLine("Please enter the common property of vehicles, leave it empty if is not important "); Console.Write("Color? "); string color = Console.ReadLine(); Console.Write("NumberOfWheels? "); string noOfWheelstring = Console.ReadLine(); if (string.IsNullOrEmpty(color) && string.IsNullOrEmpty(noOfWheelstring)) { return; } if (string.IsNullOrEmpty(color)) { do { success = int.TryParse(noOfWheelstring, out noOfWheel); if (!success || noOfWheel < 0) { Console.Clear(); Console.WriteLine("Wrong format, only numbers accepted."); Console.WriteLine("NumberOfWheels? "); noOfWheelstring = Console.ReadLine(); if (string.IsNullOrEmpty(noOfWheelstring)) { return; } } } while (!success || noOfWheel < 0); result = garage.Where(v => v.NoWheel == noOfWheel).ToList(); } if (string.IsNullOrEmpty(noOfWheelstring)) { result = garage.Where(v => v.Color == color.ToUpper() || v.Color == color.ToLower()).ToList(); } if (!string.IsNullOrEmpty(color) && !string.IsNullOrEmpty(noOfWheelstring)) { do { success = int.TryParse(noOfWheelstring, out noOfWheel); if (!success) { Console.WriteLine("Wrong format, only numbers accepted."); Console.WriteLine("NumberOfWheels? "); noOfWheelstring = Console.ReadLine(); } } while (!success); result = garage.Where(v => v.NoWheel == noOfWheel && v.Color.ToLower() == color.ToLower()).ToList(); } if (result.Count > 0) { foreach (var item in result) { //Console.Clear(); Console.WriteLine(item); } } else { Console.WriteLine($"There is not any parked car with expected information."); } } else { Console.WriteLine("Garage is empty."); } }