public IActionResult Index() { var countries = new string[] { CountryType.Sweden.ToString(), CountryType.Norway.ToString(), CountryType.Denmark.ToString(), CountryType.Finland.ToString(), }; var model = new BankStatisticsViewModel { TotalCustomers = _statisticsService.GetTotalCustomers(), TotalAccounts = _statisticsService.GetTotalAccounts(), TotalBalance = _statisticsService.GetTotalBalance(), CountryStatisticsViewModel = new CountryStatisticsViewModel { Countries = countries.Select(country => new CountryViewModel { Country = country, TotalCustomers = _statisticsService.GetTotalCustomersByCountry(country), TotalAccounts = _statisticsService.GetTotalAccountsByCountry(country), TotalBalance = _statisticsService.GetTotalBalanceByCountry(country) }).ToList() } }; return(View(model)); }
public BankStatisticsViewModel GetStats() { var model = new BankStatisticsViewModel(); model.NumberOfAccounts = _context.Accounts.Count(); model.NumberOfCustomers = _context.Customers.Count(); model.TotalAmount = _context.Accounts.Select(c => c.Balance).Sum(); return(model); }
//[Authorize(Policy = Claims.Admin)] public async Task <IActionResult> Index() { var you = new BankStatisticsViewModel(); you.TotalAccounts = await _userManager.Users.AsNoTracking().CountAsync(); you.TotalAccounts = await _context.Accounts.AsNoTracking().CountAsync(); you.TotalCustomers = await _context.Customers.AsNoTracking().CountAsync(); you.TotalBalance = await _context.Accounts.AsNoTracking().SumAsync(a => a.Balance ?? 0); return(View(you)); }