Example #1
0
        public IActionResult Index()
        {
            var loginName = User.Identity.Name;

            var accountDetails = _accountDataStore.GetAccountDetails(loginName);

            if (!string.IsNullOrEmpty(accountDetails.ErrorMessage))
            {
                ModelState.AddModelError("", "Oops. something went wrong.");
                return(View("Index"));
            }

            ViewData["AccountNumber"] = accountDetails.Data.AccountNumber;

            var wallet = _accountDataStore.GetAccountBalance(accountDetails.Data.AccountNumber);

            if (!string.IsNullOrEmpty(wallet.ErrorMessage))
            {
                ModelState.AddModelError("", "Oops. something went wrong.");
                return(View("Index"));
            }

            TempData["BalanceRowVersion"] = wallet.Data.RowVersion;

            var transactionHistory =
                _transactionDataStore.GetAccountTransactionsHistoryList(accountDetails.Data.AccountNumber);

            if (!string.IsNullOrWhiteSpace(transactionHistory.ErrorMessage))
            {
                ModelState.AddModelError("", "Oops. something went wrong.");
                return(View("Index"));
            }

            var walletTransaction = transactionHistory.Data.Select(t => new TransactionViewModel()
            {
                TransactionDateTime = t.TransactionDate,
                Description         = t.TransactionType.ToString(),
                Reference           = t.TransactionReference,
                Credit  = t.Credit,
                Debit   = t.Debit,
                Balance = t.Balance
            }).ToList();

            var viewModel = new WalletViewModel()
            {
                Balance      = wallet.Data.Balance,
                Transactions = walletTransaction
            };

            return(View(viewModel));
        }