コード例 #1
0
        public Account OpenAccount(int clientId)
        {
            try
            {
                var clientRepository = unitOfWork.GetRepository<Client>();

                if (clientRepository.All(client => client.Id != clientId))
                {
                    throw new ValidationException("The provided client id does not exist.");
                }

                var newAccount = new Account
                {
                    AccountNumber = GenerateAccountNumber(),
                    ClientId = clientId,
                    Closed = false
                };

                Validator.ValidateObject(newAccount, new ValidationContext(newAccount));
                var accountRepository = unitOfWork.GetRepository<Account>();
                accountRepository.Add(newAccount);
                unitOfWork.Commit();
                return newAccount;
            }
            catch
            {
                unitOfWork.Rollback();
                throw;
            }
        }
コード例 #2
0
        private static AccountViewModel BuildViewModel(AccountModule accountModule, Account account)
        {
            decimal balance = accountModule.GetAccountBalance(account.Id);
            Client client = accountModule.GetAccountHolder(account.Id);

            return new AccountViewModel
            {
                AccountNumber = account.AccountNumber,
                Balance = balance.ToString("C"),
                Id = account.Id,
                ClientName = client.ClientName,
                Status = account.Closed ? "Closed" : "Open",
                Closed = account.Closed
            };
        }
        private static AccountDetailsViewModel BuildViewModel(AccountService accountService, Account account)
        {
            decimal balance = accountService.GetAccountBalance(account.Id);
            IEnumerable<Transaction> ledger = accountService.GetLedger(account.Id);
            Client client = accountService.GetAccountHolder(account.Id);

            return new AccountDetailsViewModel
            {
                AccountNumber = account.AccountNumber,
                Balance = balance.ToString("C"),
                Id = account.Id,
                ClientName = client.ClientName,
                Status = account.Closed ? "Closed" : "Open",
                Ledger = ledger
            };
        }
コード例 #4
0
        private AccountViewModel BuildViewModel(Account account)
        {
            decimal balance = account.GetAccountBalance();
            Client client = clientRepository.Get(account.ClientId);

            return new AccountViewModel
            {
                AccountNumber = account.AccountNumber,
                Balance = balance.ToString("C"),
                Id = account.Id,
                ClientName = client.ClientName,
                Status = account.Closed ? "Closed" : "Open",
                Closed = account.Closed,
                Ledger = account.Ledger,
                BankCards = account.BankCards
            };
        }
コード例 #5
0
        public Account OpenAccount(int clientId)
        {
            if (clientModule.Get(clientId) == null)
            {
                throw new ValidationException("The client could not be found.");
            }

            var newAccount = new Account
            {
                AccountNumber = GenerateAccountNumber(),
                ClientId = clientId,
                Closed = false
            };

            Validator.ValidateObject(newAccount, new ValidationContext(newAccount));
            accountRepository.Add(newAccount);
            return newAccount;
        }
コード例 #6
0
 public AccountViewModel Build(Account account)
 {
     return account == null
         ? BuildInvalidAccountViewModel()
         : BuildViewModel(account);
 }