public void Debit(Money amount)
        {
            if (balance - amount < 0)
            {
                RaiseEvent(new AccountHadInsufficientFundsForDebit(amount, balance));
                return;
            }

            RaiseEvent(new AccountDebited(amount));
        }
        public void DebitAccount(AccountType accountType, Money debitAmout)
        {
            var currentBalance = GetPortfolioBalance();

            if ((currentBalance - debitAmout) < MinimumPortfolioBalance)
            {
                RaiseEvent(new PortfolioHadInsufficientFundsForDebit(debitAmout, currentBalance, MinimumPortfolioBalance));
                return;
            }

            var account = Get<Account>(new AccountId(accountType));
            account.Debit(debitAmout);
        }
        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.RaiseEvent(new PortfolioOpened());
            portfolio.OpenAccount(accountType);
            portfolio.CreditAccount(accountType, initialDeposit);

            return portfolio;
        }
 protected void When(AccountDebited e)
 {
     balance =  Money.Amount(balance - Money.Amount(e.Amount));
 }
 protected void When(AccountCredited e)
 {
     balance += Money.Amount(e.Amount);
 }
        protected override void RestoreSnapshot(IMemento memento)
        {
            var snapshot = (AccountSnapshot)memento;

            balance = snapshot.Balance;
        }
 public void CreditAccount(AccountType accountType, Money creditAmount)
 {
     GaurdPortfolioState();
     var account = Get<Account>(new AccountId(accountType));
     account.Credit(creditAmount);
 }
 public void Credit(Money amount)
 {
     RaiseEvent(new AccountCredited(amount));
 }