public IActionResult Index()
        {
            string userId = userManager.GetUserId(User);

            try
            {
                var customer = customerService.GetCustomerFromUserId(userId);
                List <BankAccountViewModel> accountViewModels = new List <BankAccountViewModel>();

                foreach (var bankAccount in customer.BankAccounts)
                {
                    accountViewModels.Add(new BankAccountViewModel
                    {
                        BankAccount = bankAccount,
                        MetaData    = metaDataService.GetMetaDataForBankAccount(bankAccount.Id)
                    });
                }
                AccountsListViewModel viewModel = new AccountsListViewModel()
                {
                    BankAccounts = accountViewModels,
                    CustomerName = $"{customer.FirstName} {customer.LastName}",
                    PhoneNo      = customer.ContactDetails?.PhoneNo
                };

                return(View(viewModel));
            }
            catch (Exception e)
            {
                //log exception
                return(BadRequest("Unable retrieve data for the current user"));
            }
        }
Example #2
0
        public IActionResult Index([FromQuery] string interval)
        {
            string userId = userManager.GetUserId(User);

            try
            {
                var customer = customerService.GetCustomerFromUserId(userId);
                List <BankAccountStatisticsViewModel> statisticsViewModels = new List <BankAccountStatisticsViewModel>();

                foreach (var bankAccount in customer.BankAccounts)
                {
                    statisticsViewModels.Add(new BankAccountStatisticsViewModel
                    {
                        BankAccount = bankAccount,
                        MetaData    = metaDataService.GetMetaDataForBankAccount(bankAccount.Id)
                    });
                }

                StatisticsViewModel viewModel = new StatisticsViewModel()
                {
                    BankAccounts = statisticsViewModels,
                    CustomerName = $"{customer.FirstName} {customer.LastName}",
                    PhoneNo      = customer.ContactDetails?.PhoneNo
                };

                logger.LogInformation("View Model created successfully");
                return(View(viewModel));
            }
            catch (Exception e)
            {
                logger.LogError("Unable to retrieve data from user {ExceptionMessage}", e);
                logger.LogDebug("Unable to retrieve data from user {@Exception}", e);

                return(BadRequest("Unable retrieve data for the current user"));
            }
        }