コード例 #1
0
        public void CreditAccount(AccountType accountType, Money amount)
        {
            GuardPortfolioState();

            var account = Get<Account>(new AccountId(accountType));
            account.Credit(amount);
        }
コード例 #2
0
        public void DebitAccount(AccountType accountType, Money amount)
        {
            GuardPortfolioState();
            GuardPortfolioBalance(accountType, amount);

            var account = Get<Account>(new AccountId(accountType));
            account.Debit(amount);
        }
コード例 #3
0
        public void Debit(Money amount)
        {
            var currentBalance = Balance();

            if ((currentBalance - amount) < 0)
            {
                throw new InvalidOperationException(String.Format("Unable to withdraw {0} as current balance is {1}", amount, currentBalance));
            }

            transactions.Add(new Transaction(amount, TransactionType.Debit));
        }
コード例 #4
0
        public static Portfolio Open(PortfolioId id, AccountType accountType, Money initialDeposit)
        {
            if (initialDeposit < MinimumPortfolioBalance)
            {
                throw new InvalidOperationException(String.Format("The intial deposit of {0} is lower than the require a minimum of {1}", initialDeposit, MinimumPortfolioBalance));
            }

            var portfolio = new Portfolio(id);
            portfolio.OpenAccount(accountType);
            portfolio.CreditAccount(accountType, initialDeposit);

            return portfolio;
        }
コード例 #5
0
        public Transaction(Money amount, TransactionType transactionType)
            : this()
        {
            if (transactionType == TransactionType.Unknown)
            {
                throw new ArgumentException("Please specify a debit or credit transaction.");
            }

            if (amount == Money.Zero)
            {
                throw new ArgumentException("A transaction cannot have a zero value.");
            }

            this.transactionType = transactionType;
            this.amount = amount;
        }
コード例 #6
0
 public void Credit(Money amount)
 {
     transactions.Add(new Transaction(amount, TransactionType.Credit));
 }
コード例 #7
0
        private void GuardPortfolioBalance(AccountType accountType, Money debitAmout)
        {
            var currentBalance = GetPortfolioBalance();

            if ((currentBalance - debitAmout) < MinimumPortfolioBalance)
            {
                throw new InvalidOperationException(String.Format("Unable to withdraw {0} from account {1} on portfolio {2} as it would exceed the portfolio balance limit of {3}",
                    debitAmout, accountType, Identity.GetId(), MinimumPortfolioBalance));
            }
        }