public static void ProductDisplay() { ProductManager productManager = new ProductManager(); Console.Title = "Shopping Cart"; Console.WriteLine($@"|--------------------------------------| | ID | Item Name | Price | |----|-------------------------|-------|"); foreach (var item in productManager.RetrieveAll()) { Console.WriteLine(item.Log()); } Console.WriteLine(@"|--------------------------------------| Please choose service: 1 - To add product to cart 2 - To decrease/delete item from cart 3 - To checkout"); Console.Write("Enter service number: "); ServiceHandler.SelectedService(ConsoleInputValidator.ServiceInputValidator()); }
/// <summary> /// Waits for the user to input a valid line, prompting the given error message until the input meets the specifications designated in the delegate /// </summary> /// <param name=""></param> /// <returns></returns> private string GetValidStringInput(ConsoleInputValidator isValid, string errorMessage) { string input = Console.ReadLine(); while (!isValid(input)) { WriteInColor(errorMessage, errorColor); Console.WriteLine(); input = Console.ReadLine(); } return(input); }
static bool ValidateGameInput(string gameInput) { var validator = new ConsoleInputValidator(); try { validator.ValidateGameInputFormat(gameInput); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine(ex.Message); Console.Write(Environment.NewLine); Console.ResetColor(); return(false); } return(true); }
public static void SelectedService(int serviceId) { ProductManager productManager = new ProductManager(); if (serviceId == 1) { Console.Write("Enter product id: "); int productId = ConsoleInputValidator.ServiceInputValidator(serviceId); int quantity = ConsoleInputValidator.QuantityInputValidator(serviceId); if (_cartManager.Retrieve(productId) != null) { _cartManager.Update(_cartManager.Retrieve(productId), serviceId, quantity); } else { _cartManager.Add(productManager.Retrieve(productId), quantity); } DisplayHandler.DisplayService(); } else if (serviceId == 2) { Console.Write("Choose which ID to decrease/remove: "); int productId = ConsoleInputValidator.ServiceInputValidator(serviceId); int quantity = ConsoleInputValidator.QuantityInputValidator(serviceId); _cartManager.Update(_cartManager.Retrieve(productId), serviceId, quantity); DisplayHandler.DisplayService(); } else if (serviceId == 3) { Console.Write("Please enter cash on hand: "); ConsoleInputValidator.ServiceInputValidator(serviceId); DoTransactionAgain(); } }