public IActionResult Index([FromQuery] string searchString) { var userId = userManager.GetUserId(User); var customer = customerService.GetCustomerFromUserId(userId); if (!String.IsNullOrEmpty(searchString)) { try { var paymentsList = paymentsService.GetFilteredPayments(userId, searchString); var viewModel = new PaymentsViewModel { BanksAccounts = customer.BankAccounts, CustomerName = $"{customer.FirstName} {customer.LastName}", CustomerPhoneNo = customer.ContactDetails?.PhoneNo, Transactions = paymentsList.OrderByDescending(payment => payment.Time) }; return(View(viewModel)); } catch (Exception e) { logger.LogError("Failed to retrieve searched payments {@Exception}", e.Message); logger.LogDebug("Failed to see payment {@ExceptionMessage}", e); return(BadRequest("Unable to process your request")); } } else { try { var viewModel = new PaymentsViewModel() { CustomerName = $"{customer.FirstName} {customer.LastName}", CustomerPhoneNo = customer.ContactDetails?.PhoneNo, BanksAccounts = customer.BankAccounts, Transactions = paymentsService.GetCustomerPayments(userId) .OrderByDescending(payment => payment.Time) }; return(View(viewModel)); } catch (Exception e) { logger.LogError("Failed to retrieve payments {@Exception}", e.Message); logger.LogDebug("Failed to see payment {@ExceptionMessage}", e); return(BadRequest("Unable to process your request")); } } }