private static void Stats(GarageHandler handler) { Console.WriteLine($"{handler.SelectedGarage}'s stats:"); var vehicletypes = handler.GetAllVehicleTypes(); var vehicles = handler.GetSelectedVehicles(); foreach (var item in vehicletypes) { Console.WriteLine($"{item}s: {vehicles.Where(x => x.ToString().StartsWith(item)).Count()}"); } }
static void Main(string[] args) { Console.CursorVisible = false; GarageHandler handler = new GarageHandler(); bool running = true; while (running) { if (handler.SelectedGarage == null) { // Create/Delete/Select a garage var menu = new List <(string, Action)>() { ("Create a new garage", () => CreateGarage(handler)) }; if (handler.AmountOfGarages > 0) { menu.Add(("Delete a garage", () => DeleteGarage(handler))); menu.Add(("Select a Garage", () => SelectGarage(handler))); } menu.Add(("-Quit-", () => running = false)); Console.WriteLine("What do you want to do?"); MenuActions(menu); } else { // Do things to the selected garage var menu = new List <(string, Action)>(); if (handler.SelectedGarageVehicleCount < handler.SelectedGarageCapacity) { menu.Add(("Add a vehicle", () => AddVehicle(handler))); } if (handler.SelectedGarageVehicleCount > 0) { menu.Add(("Stats", () => Stats(handler))); menu.Add(("List vehicles", () => ListVehicles(handler, handler.GetSelectedVehicles()))); menu.Add(("Remove a vehicle", () => RemoveVehicle(handler))); menu.Add(("Find a vehicle", () => FindVehicle(handler))); menu.Add(("Get by License plate", () => GetVehicle(handler))); } menu.Add(("-Back-", () => handler.SelectGarage(null))); Console.WriteLine($"{handler.SelectedGarage}: {handler.SelectedGarageVehicleCount}/{handler.SelectedGarageCapacity}"); Console.WriteLine("What do you want to do?"); MenuActions(menu); } } }
private static void RemoveVehicle(GarageHandler handler) { var options = handler.GetSelectedVehicles().Select(x => x.ToString()).ToList(); options.Add("-Cancel-"); Console.WriteLine("Select the vehicle to remove:"); var sel = Menu(options.ToArray()); if (sel >= options.Count) { return; } handler.DeleteVehicle(sel); }
private static void GetVehicle(GarageHandler handler) { Console.WriteLine("Please enter the vehicle's license plate: "); string input = Prompt(); var match = handler.GetSelectedVehicles().FirstOrDefault(x => x.Plate == input); if (match != null) { Console.WriteLine(match); } else { Console.WriteLine("Could not find vehicle."); } }