Exemplo n.º 1
0
        /// <summary>
        /// Returns the deposited coins to the customer
        /// </summary>
        public void ReturnCoins()
        {
            CoinReturn = new List <Coin>(CurrentTransaction);

            CurrentTransaction.Clear();

            _display.SetMessage("INSERT COIN");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the customer to select and purchase a product, assuming they have enough money and it is in stock
        /// </summary>
        /// <param name="productType"></param>
        public void SelectProduct(ProductType productType)
        {
            //ensure the product exists
            var selectedProduct = Products.Find(p => p.ProductType == productType);

            if (selectedProduct != null)
            {
                if (CurrentTransactionBalance >= selectedProduct.SellPrice && selectedProduct.StockLevel > 0)
                {
                    //too much money, so issue some change
                    if (CurrentTransactionBalance >= selectedProduct.SellPrice)
                    {
                        IssueChange(CurrentTransactionBalance - selectedProduct.SellPrice);
                    }

                    //dispense the product
                    selectedProduct.StockLevel--;
                    MachineFloat.InsertRange(0, CurrentTransaction);
                    CurrentTransaction.Clear();
                    _display.SetMessage("THANK YOU");

                    ProductDispensed = true;
                }
                else if (CurrentTransactionBalance >= selectedProduct.SellPrice && selectedProduct.StockLevel == 0)
                {
                    //no stock so display the sold out message
                    _display.SetMessage("SOLD OUT");
                }
                else
                {
                    //customer hasn't entered enough money, so remind them of the price
                    _display.SetMessage($"PRICE {selectedProduct.SellPrice.ToString("N2")}");
                    ProductDispensed = false;
                }
            }
        }