/// <summary> /// Initializes a new instance of the <see cref="SingleCurrencyWallet"/> class. /// </summary> /// <param name="regionInfo">currency region</param> /// <exception cref="ArgumentNullException">is thrown if <paramref name="regionInfo"/> is null</exception> public SingleCurrencyWallet(RegionInfo regionInfo) { if (regionInfo == null) { throw new ArgumentNullException("regionInfo"); } _currency = regionInfo.ISOCurrencySymbol; _regionInfo = regionInfo; ChangeCalculator = new ChangeCalculator(); }
/// <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(); } }