public void CreditAccount(AccountType accountType, Money amount)
        {
            GuardPortfolioState();

            var account = Get<Account>(new AccountId(accountType));
            account.Credit(amount);
        }
        public void DebitAccount(AccountType accountType, Money amount)
        {
            GuardPortfolioState();
            GuardPortfolioBalance(accountType, amount);

            var account = Get<Account>(new AccountId(accountType));
            account.Debit(amount);
        }
        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));
        }
        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;
        }
        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;
        }
 public void Credit(Money amount)
 {
     transactions.Add(new Transaction(amount, TransactionType.Credit));
 }
        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));
            }
        }