/// <summary> /// Input sequence to create a new WineItem that calls a method to add it to the WineItem array. /// </summary> /// <param name="WineCollection">WineItem[]</param> public void AddWine(WineAPI WineCollection) { string idInput = GetId(); //Check if the id the user input is all ready in the database string seachString = WineCollection.SearchByAndPossiblyDelete(idInput, nameof(Beverage.id), false); if (seachString.Contains("was not found")) { //Get the Name of the wine string descriptionInput = GetTheNameOfTheWine(); //Get the Wine pack string packInput = GetTheWinePack(); //Get the price decimal priceInputDec = GetThePrice(); //Get if the wine is active bool wineActive = BoolInput("Is this wine active"); //Now that all the input has been recieved by the user call the method to add the wine WineCollection.AddNewItem(idInput, descriptionInput, packInput, priceInputDec, wineActive); //Output the wine that has been added Console.WriteLine(WineCollection.SearchByAndPossiblyDelete(idInput, nameof(Beverage.id), false)); } else { Console.WriteLine(idInput + " is allready used as an ID. Each ID must be unique."); } }
/// <summary> /// Get id from user of wine to update and launches UpdateWine in the WineAPI using the ID /// from the user. /// </summary> /// <param name="WineCollection">WineAPI</param> public void GetUserInputToUpdateAWine(WineAPI WineCollection) { string idInput = GetId(); //Check if the id the user input is all ready in the database string seachString = WineCollection.SearchByAndPossiblyDelete(idInput, nameof(Beverage.id), false); if (seachString.Contains("was not found")) { Console.WriteLine(idInput + " Id was not found so can not be edited."); } else { //As the id was found to be used in the database launch the UpdateWine WineCollection.UpdateWine(idInput); } }
/// <summary> /// Searches the property for a value input by the user and outputs if found /// </summary> /// <param name="WineCollection">WineItem[]</param> /// <param name="propertyName">string</param> public void SearchBy(WineAPI WineCollection, string propertyName, bool delete) { string input; if (propertyName == "active") { input = BoolInput("Do you want the active wines").ToString(); } else { ColorLineNoEnter($"Enter {propertyName}: "); input = Console.ReadLine(); } if (input == "") { Console.WriteLine(WriteInvalidSpecificEntry(propertyName)); } else { Console.WriteLine(WineCollection.SearchByAndPossiblyDelete(input, propertyName, delete)); } }