internal static void DeleteVehicle(int id, GarageHandler gh, MenuHandler mh) { int beforeC = gh.GetCurrentGarage().Vehicles.Count(); Vehicle vehicle = (Vehicle)gh.TryDeleteVehicle(id); int afterC = gh.GetCurrentGarage().Vehicles.Count(); if (vehicle != null && afterC == beforeC - 1) { // ConsoleHelper.Announce("Resultat", "Fordonet har raderats" + beforeC + " " + afterC); MenuBuilder.UpdateVehicleMenu(gh, mh); mh.GoBack(); } else { ConsoleHelper.Announce("Tyvärr, Fordonet kunde inte hittas"); } }
// Todo: Ej klar! (det ska bli direkt-redigering i fordonsmenyn) internal static void EditVehicle(int id, GarageHandler gh, MenuHandler mh) { var vehicle = (Vehicle)gh.TryGetVehicle(id); if (vehicle == null) { ConsoleHelper.Announce("Kunde inte hitta fordonet med id " + id); return; } ; var action = new MenuAction(); // skrivs över int index = 0; do { Menu editMenu = new Menu("vehicleEdit", "Redigerar fordon", new List <MenuItem> { new MenuItem("Namn: " + vehicle.name, new MenuAction(Noop, "namn")), new MenuItem("Färg: " + vehicle.color, new MenuAction(Noop, "color")), new MenuItem("Vikt: " + vehicle.weight, new MenuAction(Noop, "weight")), new MenuItem("Regnr: " + vehicle.regnr, new MenuAction(Noop, "regnr")), new MenuItem(""), new MenuItem("Ta bort!", new MenuAction(Noop, "deleteVehicle")) }); editMenu.lastIndex = index; action = ConsoleHelper.RenderMenu(editMenu); Console.ForegroundColor = ConsoleColor.Cyan; //index = Console.CursorTop; switch (action.data) { case "namn": Console.SetCursorPosition(0, 3); Console.WriteLine("Ändra namn"); Console.ForegroundColor = mh.settings.ActiveColor; vehicle.name = ConsoleHelper.EditQuestionText("Namn", vehicle.name); index = 0; break; case "color": Console.SetCursorPosition(0, 3); Console.WriteLine("Ändra färg"); Console.SetCursorPosition(0, 5); Console.ForegroundColor = mh.settings.ActiveColor; vehicle.color = ConsoleHelper.EditQuestionText("Färg", vehicle.color); index = 1; break; case "weight": Console.SetCursorPosition(0, 3); Console.WriteLine("Ändra vikt"); Console.SetCursorPosition(0, 6); Console.ForegroundColor = mh.settings.ActiveColor; vehicle.weight = ConsoleHelper.EditQuestionInt("Vikt", vehicle.weight); index = 2; break; case "regnr": Console.SetCursorPosition(0, 3); Console.WriteLine("Ändra regnr"); Console.SetCursorPosition(0, 7); Console.ForegroundColor = mh.settings.ActiveColor; vehicle.regnr = ConsoleHelper.EditQuestionText("Regnr", vehicle.regnr); index = 3; break; case "deleteVehicle": gh.TryDeleteVehicle(vehicle.id); MenuBuilder.UpdateAllMenus(gh, mh); return; } Console.ForegroundColor = mh.settings.PassiveColor; // ConsoleHelper.Announce("type(" + action.type + ") (" + action.data + ") "+ action.id); } while (action.type != MenuBuilder.ActionType.Back); MenuBuilder.UpdateVehicleMenu(gh, mh); }