Exemplo n.º 1
0
        // utility
        public override string ToString()
        {
            StringBuilder sb = new StringBuilder();

            FinalizedCoffees?.ToList().ForEach(c => sb.AppendLine(c.ToString()));
            sb.AppendLine();
            sb.AppendLine($"The total cost of your order is ${GetTotalPrice()}");
            return(sb.ToString());
        }
Exemplo n.º 2
0
        // Current Working Coffee management methods
        public void FinalizeWorkingCoffee()
        {
            if (CurrentWorkingCoffee == null)
            {
                // Not really the end of the world.  Just going to log an error.
                logger.WriteError("Tried to add null working coffee to order.");
                return;
            }

            FinalizedCoffees     = FinalizedCoffees.Append(CurrentWorkingCoffee);
            CurrentWorkingCoffee = null;
        }
Exemplo n.º 3
0
        // Transaction-based methods
        public string CompleteTransaction()
        {
            // This validation calls for some refactoring
            decimal change = MoneyAdded - GetTotalPrice();

            if (!FinalizedCoffees.ToList().Any())
            {
                throw new TransactionCompletedWithoutOrdersException("A transaction cannot be completed because there are currently no coffees ordered.");
            }
            if (change < 0)
            {
                throw new InvalidMoneyException($"You have not provided sufficient money to cover the cost of the order.  Please add {change}.");
            }

            // Not sure why but couldn't get FinalizedCoffees.ToList().Clear() to work
            // Do want to get rid of this initialization here
            FinalizedCoffees = new List <ICoffee>();

            return($"Thank you for your patronage.  Your change is: {change}");
        }
Exemplo n.º 4
0
 private decimal GetTotalPrice()
 {
     return(FinalizedCoffees.Select(c => c.GetPrice()).Sum());
 }