public static string MakeChange()
        {
            StringBuilder changeToPrint = new StringBuilder();

            changeToPrint.AppendLine("---------------------------------------------------------");
            decimal remainingBalance = CustomerAccount.Balance;


            Dictionary <string, int> counter = new Dictionary <string, int>();

            while (remainingBalance > .04M)
            {
                foreach (KeyValuePair <decimal, string> kvp in Denominations)
                {
                    if (remainingBalance / kvp.Key >= 1)
                    {
                        remainingBalance -= kvp.Key;
                        if (!counter.ContainsKey(kvp.Value))
                        {
                            counter.Add(kvp.Value, 0);
                        }
                        counter[kvp.Value] += 1;
                        break;
                    }
                }
            }
            foreach (KeyValuePair <string, int> kvp in counter)
            {
                changeToPrint.AppendLine(String.Format("{0,-10} | {1,-20}", kvp.Value, kvp.Key));
            }
            FileAccess.LogItem($"GIVE CHANGE: ${CustomerAccount.Balance} ${remainingBalance}");
            CustomerAccount.Balance = 0.00M;
            return(changeToPrint.ToString());
        }
Пример #2
0
        public static string AddToCart(string PID, int amountOrdered)
        {
            if (!Inventory.ContainsKey(PID))
            {
                return("No item with that ID exists.");
            }
            int amountInInventory = Inventory[PID].InventoryAmount;

            if (amountInInventory < amountOrdered)
            {
                return("Not enough items in stock");
            }
            decimal totalPrice = Inventory[PID].Price * amountOrdered;

            if (!Transaction.RemoveMoney(totalPrice))
            {
                return("Not enough money in account.");
            }

            Inventory[PID].InventoryAmount -= amountOrdered;
            if (!Cart.ContainsKey(PID))
            {
                Cart.Add(PID, Inventory[PID]);
            }
            Cart[PID].AmountSold += amountOrdered;

            FileAccess.LogItem($"{amountOrdered} {Inventory[PID].Name} {PID} ${totalPrice} ${CustomerAccount.Balance} ");

            return("Item added");
        }
        public static bool AddMoney(decimal amountToAdd)
        {
            bool addMoney = true;

            if ((CustomerAccount.Balance + amountToAdd) > 5000.00M ||
                amountToAdd < 0)
            {
                addMoney = false;
            }
            else
            {
                addMoney = true;
                CustomerAccount.Balance += amountToAdd;
            }

            FileAccess.LogItem($"ADD MONEY: ${amountToAdd} ${CustomerAccount.Balance}");
            return(addMoney);
        }