示例#1
0
        public async Task <IActionResult> Send(String userId, [FromBody] ContactMessageDto messageDto)
        {
            if (!_validationHelper.ValidateUserPermissions(User, userId))
            {
                throw new AuthenticationException();
            }

            if (messageDto == null)
            {
                throw new Exception("Something went wrong...");
            }

            try
            {
                var message = AutoMapper.Mapper.Map <ContactMessageDoc>(messageDto);
                message.UserId = userId;
                message.Id     = Guid.NewGuid();
                await _messageRepository.AddMessage(message);

                await _emailHelper.SendMessage(message);
            }
            catch (Exception e)
            {
                throw;
            }

            return(Ok());
        }
        public async Task <IEnumerable <CreditCardDto> > GetAccountsForUser(String userId)
        {
            if (!_validationHelper.ValidateUserPermissions(User, userId))
            {
                throw new AuthenticationException();
            }

            var accounts = await _accountRepository.GetAccountsByUserId(userId) ?? new List <CreditCardDoc>();

            var needToUpdate = accounts.Any(a => DateTime.Compare(a.UpdatedOn.ToLocalTime().AddHours(28), DateTime.Now) < 0);

            if (needToUpdate)
            {
                try
                {
                    await UpdateAccounts(userId, accounts);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                accounts = await _accountRepository.GetAccountsByUserId(userId) ?? new List <CreditCardDoc>();
            }

            var result = AutoMapper.Mapper.Map <IEnumerable <CreditCardDto> >(accounts);

            return(result);
        }
示例#3
0
        public async Task <IEnumerable <MortgageDto> > GetUpdatedAccountsForUser(String userId)
        {
            if (!_validationHelper.ValidateUserPermissions(User, userId))
            {
                throw new AuthenticationException();
            }

            var loans = await _mortgageRepository.GetLoansByUserId(userId) ?? new List <MortgageDoc>();

            var needToUpdate = loans.Any(a => DateTime.Compare(a.UpdatedOn.ToLocalTime().AddHours(28), DateTime.Now) < 0);

            if (needToUpdate)
            {
                try
                {
                    await UpdateLoans(userId, loans);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }

                loans = await _mortgageRepository.GetLoansByUserId(userId) ?? new List <MortgageDoc>();
            }

            return(AutoMapper.Mapper.Map <IEnumerable <MortgageDto> >(loans));
        }
示例#4
0
        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));
        }
示例#5
0
        public async Task <IActionResult> GetAgregatedTransactionsByDate(String userId,
                                                                         [FromQuery(Name = "aggregated")] bool isAggregated,
                                                                         [FromQuery(Name = "year")] int year, [FromQuery(Name = "month")] int month)
        {
            IEnumerable <TransactionDto> result;

            if (!_validationHelper.ValidateUserPermissions(User, userId))
            {
                throw new AuthenticationException();
            }

            var transactions = await GetTransactionsForUser(userId, year, month);

            try
            {
                result = AutoMapper.Mapper.Map <IEnumerable <TransactionDto> >(transactions);
            }
            catch (Exception e)
            {
                throw;
            }

            return(Ok(result));
        }
示例#6
0
        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[]>()
            });
        }