Ejemplo n.º 1
0
        public void CloseAccount(AccountId accountId, Payment payment)
        {
            var userAccount = UserAccounts.Single(x => x.AccountId == accountId);

            if (userAccount.State == UserAccount.UserAccountEnum.Closed)
            {
                throw new InvalidOperationException("Account is already closed");
            }

            Apply(new V1.AccountClosed(Id, accountId.Value, payment.Amount, payment.CurrencyCode));

            //If all acounts are closed now, we also should finalize the clearance
            if (!UserAccounts.Exists(x => x.State == UserAccount.UserAccountEnum.Open))
            {
                FinalizeClearance();
            }
        }