public void populateQuantities() { Instruction currentInstruction; Ingredient currentIngredient; for (int i = 0; i < MyInstructions.Count(); i++) { bool finish = false; currentInstruction = MyInstructions[i]; currentInstruction.setOrder(i + 1); Console.WriteLine("Instruction #: " + (i + 1)); currentInstruction.printInstructionToConsole(); currentInstruction.setOrder(i); while (finish == false) { int ingredientCount = MyIngredients.Count(); Console.WriteLine("Available Ingredients: "); for (int e = 0; e < MyIngredients.Count(); e++) { Console.WriteLine("Positition: " + e); currentIngredient = MyIngredients[e]; currentIngredient.printIngredient(); } Console.WriteLine("Select the ingredient to go with the instruction by position or 'continue' to exit"); string userInput = Console.ReadLine(); userInput = userInput.Trim(); if (userInput == "continue") { finish = true; } else { Ingredient ingredient = new Ingredient(); try { //ingredient = MyIngredients.Single(x => x.getId() == Convert.ToInt32(userInput)); //how do we deal with multiple things with the same name, b/c we dont have primary keys for //all ingredients int userInputInt = 0; bool parse2 = Int32.TryParse(userInput, out userInputInt); if (parse2) { ingredient = MyIngredients[userInputInt]; } } catch { // ingredient = new Ingredient(); Console.WriteLine("UserInput Error: ID=USERID != 2 reality"); } ingredient.printIngredient(); Console.WriteLine("Select the quantity of the ingredient"); userInput = Console.ReadLine(); decimal quantity; bool parse = Decimal.TryParse(userInput, out quantity); if (parse == false) { quantity = 99999987; } ingredient.setQuantity(quantity); currentInstruction.addIngredient(ingredient); } } } }
public void setIngredientsInRecipe(List <Ingredient> totalIngredients, int userID) { Console.WriteLine("Ingredients in My Recipe: " + MyIngredients.Count); bool finish = false; Console.WriteLine("Create new Ingredient (create) or add from list (add)?"); string userInput2 = Console.ReadLine(); if (userInput2 == "add") { Console.WriteLine("Print the Ingredient Name from the List: "); string userInput = Console.ReadLine(); userInput = userInput.Trim(); Ingredient hold = new Ingredient(); List <Ingredient> tempList = new List <Ingredient>(); foreach (Ingredient temp in totalIngredients) { if (userInput == temp.getName()) { tempList.Add(temp); hold = temp; // Console.WriteLine("duplicate"); } } // Console.WriteLine("ingredient count" + tempList.Count); if (tempList.Count > 1) { for (int d = 0; d < tempList.Count; d++) { Console.WriteLine("Position: " + d); tempList[d].printIngredient(); } Console.WriteLine("Please Select an ingredient by position"); string uInput = Console.ReadLine(); int uInputInt = 0; bool par = Int32.TryParse(uInput, out uInputInt); hold = tempList[uInputInt]; if (!par) { Console.WriteLine("User Error, input non-int"); } } hold.printIngredient(); MyIngredients.Add(hold); } if (userInput2 == "create") { createIngredient(userID); } Console.WriteLine("MyIngredients count after " + MyIngredients.Count); Console.WriteLine("Done adding Ingredients? (Y/N)"); string userInput3 = Console.ReadLine(); userInput3 = userInput3.ToLower(); if (userInput3 == "y") { finish = true; } if (finish == false) { setIngredientsInRecipe(totalIngredients, userID); } }