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); }
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)); }
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); }
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); }
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); }
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); }
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); }