public async Task <CustomerResult> GetCustomer(Guid customerId) { Customer customer = await _context .Customers .Find(e => e.Id == customerId) .SingleOrDefaultAsync(); if (customer == null) { throw new CustomerNotFoundException($"The customer {customerId} does not exists or is not processed yet."); } List <Guid> accountIds = await _context .Accounts .Find(e => e.CustomerId == customerId) .Project(p => p.Id) .ToListAsync(); List <AccountResult> accountsResult = new List <AccountResult>(); foreach (Guid accountId in accountIds) { AccountResult accountResult = await _accountsQueries.GetAccount(accountId); accountsResult.Add(accountResult); } CustomerResult customerResult = new CustomerResult( customer.Id, customer.Name, customer.SSN, accountsResult); return(customerResult); }
public async Task <CustomerResult> GetCustomer(Guid customerId) { Customer customer = _context .Customers .Where(e => e.Id == customerId) .SingleOrDefault(); if (customer == null) { throw new CustomerNotFoundException($"The customer {customerId} does not exists or is not processed yet."); } List <AccountResult> accountsResult = new List <AccountResult>(); foreach (Guid accountId in customer.Accounts) { AccountResult accountResult = await _accountsQueries.GetAccount(accountId); accountsResult.Add(accountResult); } CustomerResult customerResult = new CustomerResult( customer.Id, customer.Name, customer.SSN, accountsResult); return(await Task.FromResult <CustomerResult>(customerResult)); }
public async Task <CustomerResult> GetCustomer(Guid customerId) { using (IDbConnection db = new SqlConnection(_connectionString)) { string customerSQL = "SELECT * FROM Customer WHERE Id = @customerId"; Entities.Customer customer = await db .QueryFirstOrDefaultAsync <Entities.Customer>(customerSQL, new { customerId }); if (customer == null) { return(null); } string accountSQL = "SELECT id FROM Account WHERE CustomerId = @customerId"; IEnumerable <Guid> accounts = await db .QueryAsync <Guid>(accountSQL, new { customerId }); List <AccountResult> accountCollection = new List <AccountResult>(); foreach (Guid accountId in accounts) { accountCollection.Add(await _accountsQueries.GetAccount(accountId)); } CustomerResult customerResult = new CustomerResult(customer.Id, customer.Name, customer.SSN, accountCollection); return(customerResult); } }
public async Task <CustomerResult> GetCustomer(Guid customerId) { Entities.Customer customer = await _context .Customers .FindAsync(customerId); List <Entities.Account> accounts = await _context .Accounts .Where(e => e.CustomerId == customerId) .ToListAsync(); if (customer == null) { throw new CustomerNotFoundException($"The customer {customerId} does not exists or is not processed yet."); } List <AccountResult> accountsResult = new List <AccountResult>(); foreach (Account account in accounts) { AccountResult accountResult = await _accountsQueries.GetAccount(account.Id); accountsResult.Add(accountResult); } CustomerResult customerResult = new CustomerResult( customer.Id, customer.Name, customer.SSN, accountsResult); return(await Task.FromResult <CustomerResult>(customerResult)); }
public async Task <IActionResult> Get(Guid accountId) { var account = await accountsQueries.GetAccount(accountId); List <TransactionModel> transactions = new List <TransactionModel>(); foreach (var item in account.Transactions) { var transaction = new TransactionModel( item.Amount, item.Description, item.TransactionDate); transactions.Add(transaction); } return(new ObjectResult(new AccountDetailsModel( account.AccountId, account.CurrentBalance, transactions))); }
public async Task <IActionResult> Get(Guid accountId) { var account = await accountsQueries.GetAccount(accountId); return(Ok(account)); }