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.Aadhar,
                                                                   accountCollection);

                return(customerResult);
            }
        }
Esempio n. 2
0
        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.Aadhar,
                accountsResult);

            return(await Task.FromResult <CustomerResult>(customerResult));
        }
        public async Task <CustomerResult> GetCustomer(Guid customerId)
        {
            Customer customer = await _context.Customers
                                .Find(customer => customer.Id == customerId).SingleOrDefaultAsync();

            if (customer == null)
            {
                throw new CustomerNotFoundException($"The {customerId} does not exist");
            }

            List <Guid> accountIds = await _context
                                     .Accounts
                                     .Find(e => e.CustomerId == customerId)
                                     .Project(p => p.Id)
                                     .ToListAsync();

            List <AccountResult> accountResults = new List <AccountResult>();

            foreach (Guid accountId in accountIds)
            {
                AccountResult accountResult = await _accountQueries.GetAccount(accountId);

                accountResults.Add(accountResult);
            }

            CustomerResult customerResult = new CustomerResult(customer.Id, customer.Name, customer.Aadhar, accountResults);

            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.Aadhar,
                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)));
        }
Esempio n. 6
0
        public async Task <IActionResult> Get(System.Guid accountId)
        {
            var account = await _accountQueries.GetAccount(accountId);

            return(Ok(account));
        }