public void Populate(AccountOutput output) { if (output == null) { ViewModel = new NoContentResult(); return; } List <TransactionModel> transactions = new List <TransactionModel>(); foreach (var item in output.Transactions) { var transaction = new TransactionModel( item.Amount, item.Description, item.TransactionDate); transactions.Add(transaction); } ViewModel = new ObjectResult(new AccountDetailsModel( output.AccountId, output.CurrentBalance, transactions)); }
public async Task <IActionResult> Get(Guid accountId) { AccountOutput output = await _getAccountDetailsUseCase.Execute(accountId); _presenter.Populate(output); return(_presenter.ViewModel); }
public async Task <CustomerOutput> Execute(Guid customerId) { Customer customer = await _customerReadOnlyRepository.Get(customerId); if (customer == null) { throw new CustomerNotFoundException($"The customer {customerId} does not exists or is not processed yet."); } List <AccountOutput> accounts = new List <AccountOutput> (); foreach (Guid accountId in customer.Accounts.ToReadOnlyCollection()) { Account account = await _accountReadOnlyRepository.Get(accountId); if (account != null) { AccountOutput accountOutput = new AccountOutput(account); accounts.Add(accountOutput); } } CustomerOutput output = new CustomerOutput(customer, accounts); return(output); }
public ApiResult <IList <AccountOutput> > AllAccounts([FromQuery] ApiBaseInput parameter) { var httpss = HttpContext.Request.QueryString; var model = Resolve <IAccountService>().GetUserAllAccount(parameter.LoginUserId); var moneys = Resolve <IAutoConfigService>().MoneyTypes(); IList <AccountOutput> result = new List <AccountOutput>(); foreach (var item in model) { var config = moneys.FirstOrDefault(r => r.Id == item.MoneyTypeId && r.IsShowFront && r.Status == Status.Normal); if (config != null) { var apiOutput = new AccountOutput { MoneyTypeName = config.Name, Amount = item.Amount, MoneyTypeId = item.MoneyTypeId }; result.Add(apiOutput); } } return(ApiResult.Success(result)); }
public async Task <AccountOutput> Execute(Guid accountId) { Account account = await _accountReadOnlyRepository.Get(accountId); if (account == null) { throw new AccountNotFoundException($"The account {accountId} does not exists or is not processed yet."); } AccountOutput output = new AccountOutput(account); return(output); }
public async Task Process(GetAccountDetailsInput input) { Account account = await accountReadOnlyRepository.Get(input.AccountId); if (account == null) { throw new AccountNotFoundException($"The account {input.AccountId} does not exists or is already closed."); } AccountOutput output = outputConverter.Map <AccountOutput>(account); outputBoundary.Populate(output); }
public async Task Process(GetAccountDetailsInput input) { var account = await accountReadOnlyRepository.Get(input.AccountId); if (account == null) { outputBoundary.Populate(null); return; } AccountOutput output = outputConverter.Map <AccountOutput>(account); outputBoundary.Populate(output); }
public async Task GetAccountDetails_ValidId_ShouldReturnAnAccount() { //ARRANGE var accountId = Guid.NewGuid(); Account account = BuildAccount(accountId); _accountReadOnlyRepository.Setup(m => m.Get(account.Id)).Returns(Task.FromResult(account)); //ACT AccountOutput outPut = await getAccountDetailsUseCase.Execute(account.Id); //ASSERT _accountReadOnlyRepository.Verify(v => v.Get(account.Id), Times.Once()); Assert.Equal(account.Id, outPut.AccountId); Assert.NotEmpty(outPut.Transactions); }
public async Task Process(RegisterInput message) { Customer customer = new Customer(message.PIN, message.Name); Account account = new Account(); account.Open(customer.Id, new Credit(account.Id, message.InitialAmount)); customer.Register(account.Id); var customerEvents = customer.GetEvents(); var accountEvents = account.GetEvents(); await bus.Publish(customerEvents); await bus.Publish(accountEvents); // // To ensure the Customer and Account are created in the database // we wait for the records be available in the following queries // with retry // bool consumerReady = await RetryGet(async() => await customerReadOnlyRepository.Get(customer.Id)) && await RetryGet(async() => await accountReadOnlyRepository.Get(account.Id)); if (!consumerReady) { customer = null; account = null; // // TODO: Throw exception, monitor the inconsistencies and fail fast. // } CustomerOutput customerOutput = responseConverter.Map <CustomerOutput>(customer); AccountOutput accountOutput = responseConverter.Map <AccountOutput>(account); RegisterOutput output = new RegisterOutput(customerOutput, accountOutput); outputBoundary.Populate(output); }
public async Task Process(RegisterInput input) { Customer customer = new Customer(input.PIN, input.Name); Account account = new Account(customer.Id); Credit credit = new Credit(account.Id, input.InitialAmount); account.Deposit(credit); customer.Register(account.Id); await customerWriteOnlyRepository.Add(customer); await accountWriteOnlyRepository.Add(account, credit); CustomerOutput customerOutput = outputConverter.Map <CustomerOutput>(customer); AccountOutput accountOutput = outputConverter.Map <AccountOutput>(account); RegisterOutput output = new RegisterOutput(customerOutput, accountOutput); outputBoundary.Populate(output); }
public RegisterOutput(Customer customer, Account account) { List <TransactionOutput> transactionOutputs = new List <TransactionOutput> (); foreach (ITransaction transaction in account.Transactions.ToReadOnlyCollection()) { transactionOutputs.Add( new TransactionOutput( transaction.Description, transaction.Amount, transaction.TransactionDate)); } Account = new AccountOutput(account.Id, account.GetCurrentBalance(), transactionOutputs); List <AccountOutput> accountOutputs = new List <AccountOutput> (); accountOutputs.Add(Account); Customer = new CustomerOutput(customer, accountOutputs); }
public void Populate(AccountOutput output, Controller controller) { List <TransactionModel> transactions = new List <TransactionModel>(); foreach (var item in output.Transactions) { var transaction = new TransactionModel( item.Amount, item.Description, item.TransactionDate); transactions.Add(transaction); } AccountDetailsModel account = new AccountDetailsModel( output.AccountId, output.CurrentBalance, transactions); ViewModel = controller.View(account); }
public async Task Process(GetCustomerDetailsInput input) { // // TODO: The following queries could be simplified // Customer customer = await customerReadOnlyRepository.Get(input.CustomerId); if (customer == null) { throw new CustomerNotFoundException($"The customer {input.CustomerId} does not exists or is not processed yet."); } List <AccountOutput> accounts = new List <AccountOutput>(); foreach (var accountId in customer.Accounts) { Account account = await accountReadOnlyRepository.Get(accountId); // // TODO: The "Accout closed state" is not propagating to the Customer Aggregate // if (account != null) { AccountOutput accountOutput = outputConverter.Map <AccountOutput>(account); accounts.Add(accountOutput); } } CustomerOutput output = outputConverter.Map <CustomerOutput>(customer); output = new CustomerOutput( customer.Id, customer.PIN.Text, customer.Name.Text, accounts); outputBoundary.Populate(output); }
public RegisterOutput(CustomerOutput customer, AccountOutput account) { Customer = customer; Account = account; }