Exemple #1
0
        /// <summary>
        /// Deposit the given value into the Piggy Bank balance
        /// </summary>
        /// <param name="value"></param>
        public void Deposit(decimal value)
        {
            //Allow only greater than zero
            if (value <= 0)
            {
                throw new ArgumentException(Properties.Resources.ValueMustBeGreaterThanZero);
            }

            //Create transaction
            PiggyBankTransaction transaction = new PiggyBankTransaction(value);

            //Add transaction to piggy bank transactions list
            _transactions[transaction.Id] = transaction;

            AddDomainEvent(new PiggyBankDepositRegisteredDomainEvent(transaction));
        }
Exemple #2
0
        /// <summary>
        /// Withraw the given value from the Piggy Bank balance
        /// </summary>
        /// <param name="value"></param>
        public void Withdraw(decimal value)
        {
            //To allow recieving positive or negative value
            if (value > 0)
            {
                value *= -1m;
            }

            //Verify sufficient balance
            if ((CurrentBalance + value) < 0)
            {
                throw new InvalidOperationException(Properties.Resources.InsufficientBalanceToWithdraw);
            }

            //Create transaction
            PiggyBankTransaction transaction = new PiggyBankTransaction(value);

            //Add transaction to piggy bank transactions list
            _transactions[transaction.Id] = transaction;

            AddDomainEvent(new PiggyBankWithdrawRegisteredDomainEvent(transaction));
        }