Пример #1
0
        public async Task <ActionResult <Customer> > GetCustomerInfoByCustomerId(
            [SwaggerParameter("Customer identifier", Required = true)] int customerId)
        {
            _logger.LogInformation($"Get customer info for a {customerId}");

            try
            {
                if (customerId <= 0)
                {
                    _logger.LogWarning($"Invalid customer id: {customerId}");
                    return(BadRequest());
                }

                Customer customer = _mapper.Map <Customer>(_customerAccountRepository.GetCustomer(customerId));

                if (customer == null)
                {
                    _logger.LogWarning($"No customer info found for customer {customerId}");
                    return(NotFound());
                }

                List <CustomerAccount> customerAccounts = _mapper.Map <List <CustomerAccount> >(_customerAccountRepository.GetCustomerAccountsByCustomerId(customerId));

                if (customerAccounts == null)
                {
                    return(Ok(customer));
                }

                customer.Balance = customerAccounts.Sum(c => c.Balance);

                foreach (var customerAccount in customerAccounts)
                {
                    customerAccount.Transactions = await _transactionProxyService.GetTransactions(customerAccount.CustomerAccountId);
                }

                customer.customerAccounts = customerAccounts;

                return(Ok(customer));
            }
            catch (Exception ex)
            {
                _logger.LogError($"Error in {nameof(GetCustomerInfoByCustomerId)} with customerId {customerId}. Details: {ex}");
                return(StatusCode(500));
            }
        }