/// <summary> /// Updates part of a skateboard that the user can pick . /// </summary> public void SkateboardUpdate() { CsvReader store = new CsvReader(); //Loads the parts from the csv file. store.LoadEverything(); UI.Printer("Type in the name of the skateboard you want to update "); string name = UI.Scanner(); //Check if there is a board with the name that the user gave GetSkateboardByName(name); for (int i = 0; i < Skateboards.Count; i++) { //Iterates through the storage and searches for the matching name if (Skateboards[i].name.ToLower().Equals(name.ToLower())) { UI.Printer("Which hardware do you want to change?(Deck,Truck,Wheels,Griptape,Bearings)"); string hardwareType = UI.Scanner(); switch (hardwareType.ToLower()) { case "deck": { while (true) { Console.Clear(); Hardware.Deck deck = DeckForAssembly(store); try { Hardware.Deck deckReturnable = (Hardware.Deck)Skateboards[i].PartInStore(store, deck); if (!deckReturnable.Equals(null)) { Skateboards[i].deck = deckReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } break; } case "truck": { while (true) { Console.Clear(); Hardware.Truck truck = TruckForAssembly(store); try { Hardware.Truck truckReturnable = (Hardware.Truck)Skateboards[i].PartInStore(store, truck); if (!truckReturnable.Equals(null)) { Skateboards[i].truck = truckReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } break; } case "wheels": { while (true) { Console.Clear(); Hardware.Wheels wheels = WheelsForAssembly(store); try { Hardware.Wheels wheelsReturnable = (Hardware.Wheels)Skateboards[i].PartInStore(store, wheels); if (!wheelsReturnable.Equals(null)) { Skateboards[i].wheel = wheelsReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } break; } case "bearings": { while (true) { Console.Clear(); Hardware.Bearings bearings = BearingsForAssembly(store); try { Hardware.Bearings bearingsReturnable = (Hardware.Bearings)Skateboards[i].PartInStore(store, bearings); if (!bearingsReturnable.Equals(null)) { Skateboards[i].bearings = bearingsReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } break; } case "griptape": { while (true) { Console.Clear(); Hardware.Griptape griptape = GriptapeForAssembly(store); try { Hardware.Griptape griptapeReturnable = (Hardware.Griptape)Skateboards[i].PartInStore(store, griptape); if (!griptapeReturnable.Equals(null)) { Skateboards[i].griptape = griptapeReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } break; } default: { UI.PrintErrorMessage("That's not a valid hardware!"); break; } } } } }
/// <summary> /// Creates a new skateboard instance, with parts chosen by the user /// </summary> /// <returns></returns> public Skateboard SkateboardAssembly() { Console.Clear(); CsvReader store = new CsvReader(); //Loads hardware from the csv file store.LoadEverything(); Skateboard skateboard = new Skateboard(); //Checks if the given name already exists in the storage. Throws exception if it does. string name; while (true) { try { name = CheckIfBoardNameExists(UI.GetNameOfBoard()); break; } catch (Exceptions.NameExistsException) { UI.PrintErrorMessage("This name already exists."); } } skateboard.name = name; while (true) { Console.Clear(); Hardware.Deck deck = DeckForAssembly(store); try { //Gets the chosen deck from the store and puts it in deckReturnable . Hardware.Deck deckReturnable = (Hardware.Deck)skateboard.PartInStore(store, deck); if (!deckReturnable.Equals(null)) { skateboard.deck = deckReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } while (true) { Console.Clear(); Hardware.Griptape griptape = GriptapeForAssembly(store); try { Hardware.Griptape griptapeReturnable = (Hardware.Griptape)skateboard.PartInStore(store, griptape); if (!griptapeReturnable.Equals(null)) { skateboard.griptape = griptapeReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } while (true) { Console.Clear(); Hardware.Truck truck = TruckForAssembly(store); try { Hardware.Truck truckReturnable = (Hardware.Truck)skateboard.PartInStore(store, truck); if (!truckReturnable.Equals(null)) { skateboard.truck = truckReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } while (true) { Console.Clear(); Hardware.Wheels wheels = WheelsForAssembly(store); try { Hardware.Wheels wheelsReturnable = (Hardware.Wheels)skateboard.PartInStore(store, wheels); if (!wheelsReturnable.Equals(null)) { skateboard.wheel = wheelsReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } while (true) { Console.Clear(); Hardware.Bearings bearings = BearingsForAssembly(store); try { Hardware.Bearings bearingsReturnable = (Hardware.Bearings)skateboard.PartInStore(store, bearings); if (!bearingsReturnable.Equals(null)) { skateboard.bearings = bearingsReturnable; break; } } catch (NullReferenceException) { UI.PrintErrorMessage("There is no skateboard part with the given arguments. When typing a float number use a decimal point!"); } } return(skateboard); }