public async Task <IEnumerable <BankAccountDto> > GetUpdatedAccountsForUser(String userId) { if (!_validationHelper.ValidateUserPermissions(User, userId)) { throw new AuthenticationException(); } var accounts = await _accountRepository.GetAccountsByUserId(userId) ?? new List <BankAccountDoc>(); var accountsToUpdate = accounts .Where(a => DateTime.Compare(a.UpdatedOn.ToLocalTime().AddDays(1), DateTime.Now) < 0) .Select(account => account.Id); if (accountsToUpdate.Any()) { try { await UpdateAccounts(userId, accountsToUpdate); } catch (Exception e) { Console.WriteLine(e); } accounts = await _accountRepository.GetAccountsByUserId(userId) ?? new List <BankAccountDoc>(); } return(AutoMapper.Mapper.Map <IEnumerable <BankAccountDto> >(accounts)); }
private async Task <IEnumerable <TransactionDoc> > GetBankTransactionsForUser(String userId, int year, int month) { var banksAccounts = await _bankAccountRepository.GetAccountsByUserId(userId) ?? new List <BankAccountDoc>(); List <TransactionDoc> transactions = new List <TransactionDoc>(); foreach (var banksAccount in banksAccounts) { var trs = GetTransactionsForAccount(banksAccount.Id, year, month).Result; transactions.AddRange(trs); } return(transactions); }
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[]>() }); }