public async Task <OverviewDto> GetOverview(String userId) { if (!_validationHelper.ValidateUserPermissions(User, userId)) { throw new AuthenticationException(); } var expenses = new Dictionary <String, Decimal>(); //institution vs amount last 30 days var incomes = new Dictionary <String, Decimal>(); //institution vs amount last 30 days var cashFlowExpenses = new Dictionary <String, Decimal>(); //month vs amount last 6 months var cashFlowIncomes = new Dictionary <String, Decimal>(); //month vs amount last 6 months var institutions = new List <InstitutionOverviewDto>(); var mortgageOverview = new LoanOverviewDto(); var loanOverview = new LoanOverviewDto(); int numberOfMortgages = 0; int numberOfLoans = 0; Decimal netWorth = 0; InitCashFlowDictionary(cashFlowExpenses); InitCashFlowDictionary(cashFlowIncomes); var bankAccounts = await _bankAccountRepository.GetAccountsByUserId(userId); foreach (var account in bankAccounts) { GenerateNetWorthFromBank(account, incomes, expenses); GenerateCashFlowFromBank(account, cashFlowIncomes, cashFlowExpenses); numberOfMortgages += GenerateMortgageFromBank(account, mortgageOverview); numberOfLoans += GenerateLoanFromBank(account, loanOverview); netWorth += account.Balance; institutions.Add(new InstitutionOverviewDto { Label = account.Label, ProviderName = account.ProviderName, Balance = account.Balance }); } var creditCards = await _creditAccountRepository.GetCardsByUserId(userId); foreach (var account in creditCards) { GenerateNetWorthFromCredit(account, incomes, expenses); netWorth += incomes[account.LastDigits] - expenses[account.LastDigits]; institutions.Add(new InstitutionOverviewDto { Label = account.LastDigits, ProviderName = account.ProviderName, Balance = incomes[account.LastDigits] - expenses[account.LastDigits] }); } return(new OverviewDto { NetWorth = netWorth, ListOfInstitutions = institutions, NetWorthIncomes = incomes, NetWorthExpenses = expenses, CashFlowIncomes = cashFlowIncomes, CashFlowExpenses = cashFlowExpenses, MortgageOverview = mortgageOverview, LoanOverview = loanOverview, NumberOfMortgages = numberOfMortgages, NumberOfLoans = numberOfLoans, Loans = new List <Decimal[]>(), Mortgages = new List <Decimal[]>() }); }