Exemplo n.º 1
0
        public virtual bool CanBuySnack(int position)
        {
            ValidationMessages.Clear();

            var snackPile = GetSnackPile(position);

            if (snackPile.Quantity == 0)
            {
                ValidationMessages.Add(Constants.NoSnackAvailableToBuy);
                return(false);
            }

            if (snackPile.Price > MoneyInTransaction)
            {
                ValidationMessages.Add(Constants.NotEnoughMoneyInserted);
                return(false);
            }

            if (!MoneyInside.CanAllocate(snackPile.Price))
            {
                ValidationMessages.Add(Constants.NotEnoughChange);
                return(false);
            }

            return(true);
        }
Exemplo n.º 2
0
        public virtual void TakeMoney(decimal amount)
        {
            if (!MoneyInside.CanAllocate(amount))
            {
                throw new InvalidOperationException();
            }

            var allocatedMoney = MoneyInside.Allocate(amount);

            MoneyInside -= allocatedMoney;
            decimal amountWithCommision = CalculateAmountWithCommision(amount);

            MoneyCharged += amountWithCommision;
            AddDomainEvent(new BalanceChangedEvent(amountWithCommision));
        }
Exemplo n.º 3
0
 public string CanTakeMoney(decimal amount)
 {
     if (amount <= 0)
     {
         return("Invalid amount");
     }
     if (MoneyInside.Amount < amount)
     {
         return("Not enough money");
     }
     if (!MoneyInside.CanAllocate(amount))
     {
         return("Not enough change");
     }
     return(string.Empty);
 }
Exemplo n.º 4
0
        public virtual string CanBuySnack(int position)
        {
            var snackPile = GetSnackPile(position);

            if (snackPile.Quantity == 0)
            {
                return("The snack pile is empty.");
            }
            if (MoneyInTransaction < snackPile.Price)
            {
                return("Not enough money.");
            }
            if (!MoneyInside.CanAllocate(MoneyInTransaction - snackPile.Price))
            {
                return("Not enough change.");
            }
            return(string.Empty);
        }
Exemplo n.º 5
0
        private bool CanTakeMoney(decimal amount)
        {
            if (amount <= 0)
            {
                throw new InvalidOperationException();
            }

            if (MoneyInside.Amount < amount)
            {
                throw new InvalidOperationException();
            }

            if (!MoneyInside.CanAllocate(amount))
            {
                throw new InvalidOperationException();
            }

            return(true);
        }
Exemplo n.º 6
0
        public bool CanBuySnak(int position)
        {
            var slot = GetSlot(position);

            if (slot.GetItemsQuantity() < 0)
            {
                return(false);
            }

            if (MoneyInTransaction.Amount < slot.GetItemPrice())
            {
                return(false);
            }

            var chargeToAllocate = MoneyInTransaction.Amount - slot.GetItemPrice();

            if (!MoneyInside.CanAllocate(chargeToAllocate))
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 7
0
        public virtual bool CanWithdrawal(decimal amount)
        {
            ValidationMessages.Clear();

            if (amount <= 0m)
            {
                ValidationMessages.Add(Constants.InvalidAmount);
                return(false);
            }

            if (amount > MoneyInside.Amount)
            {
                ValidationMessages.Add(Constants.NotEnoughChange);
                return(false);
            }

            if (!MoneyInside.CanAllocate(amount))
            {
                ValidationMessages.Add(Constants.NotEnoughChange);
                return(false);
            }

            return(true);
        }