Beispiel #1
0
        private static void CreateGarage(GarageHandler handler)
        {
            Console.WriteLine("Please enter a name for the garage: (enter nothing to cancel)");
            string name = Prompt();

            if (string.IsNullOrWhiteSpace(name))
            {
                return;
            }
            if (handler.Garages.Any(x => x == name))
            {
                Console.WriteLine($"A Garage with the name '{name}' already exists");
                return;
            }

            string capacityInput;
            int    capacity;

            do
            {
                Console.WriteLine("Please enter the capacity of the garage: (enter '-1' to cancel)");
                capacityInput = Prompt();
            } while (!Int32.TryParse(capacityInput, out capacity));
            if (capacity >= 0)
            {
                handler.CreateGarage(name, capacity);
                handler.SelectGarage(name);
            }
            return;
        }
Beispiel #2
0
        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);
                }
            }
        }
Beispiel #3
0
        private static void SelectGarage(GarageHandler handler)
        {
            var entries = handler.FormattedGarageList.ToList();

            entries.Add("-Cancel-");

            Console.WriteLine("Select a garage:");
            int sel = Menu(entries.ToArray());

            if (sel < entries.Count - 1)
            {
                handler.SelectGarage(handler.Garages.Skip(sel).First());
            }
        }