/// <summary> /// Shows and returns all products from the database /// </summary> /// <returns>product database</returns> private static ProductsDatabase ShowProducts() { Output(welcomeText); ShowCredit(); ProductsDatabase products = new ProductsDatabase(); Output(products.Show()); return(products); }
/// <summary> /// Start machine logic /// </summary> public static void StartMachine() { Console.Clear(); bool end = false; do { ProductsDatabase products = ShowProducts(); Pay(); if (isAdmin) { AdminLogic.StartAdminLogic(); } ShowCredit(); Output(products.Show()); ChooseProduct(products); EndTransaction(); end = true; } while (!end); Pause(); }
/// <summary> /// Choose a product from the database /// </summary> /// <param name="products">database to choose from</param> public static void ChooseProduct(ProductsDatabase products) { bool choosedProduct = false; int prod = 0; double productCost; Int64 productQuantity; int length = products.Products.Count; do { Console.Clear(); ShowCredit(); Output(products.Show()); Output(chooseProduct); try { prod = int.Parse(Input()); if (length >= prod) { choosedProduct = true; } else { choosedProduct = false; Output(wrongNumber); Thread.Sleep(2500); } } catch (System.FormatException) { choosedProduct = false; Output(wrongFormat); Thread.Sleep(2500); } } while (!choosedProduct); productQuantity = products.Products[prod - 1].Quantity; if (productQuantity > 0) { productCost = products.Products[prod - 1].Price; //check if price is lower or equal to credit if (productCost > fullMoney) { Output(notEnoughMoney); Thread.Sleep(2500); Console.Clear(); Pay(); } else { fullMoney = ChangeCalculator.CalculateChange(fullMoney, (float)productCost); ProductsDatabase.Decrement(prod, products); TransactionsDatabase.AddTransaction(prod); Console.Clear(); } } else { Output(itemUnavailable); EndTransaction(); Pause(); StartMachine(); } }