コード例 #1
0
 public async Task AddAccount(BankAccountDoc item)
 {
     try
     {
         await _context.BankAccounts.InsertOneAsync(item);
     }
     catch (Exception ex)
     {
         // log or manage the exception
         throw ex;
     }
 }
コード例 #2
0
        private async Task <IEnumerable <TransactionDoc> > UpdateNewTransactions(
            BankAccountDoc account, IEnumerable <BankTransaction> transactions, DateTime date)
        {
            var newTransactions = AutoMapper.Mapper.Map <IEnumerable <TransactionDoc> >(transactions).ToList();

            account.Transactions.ToList()
            .RemoveAll(t => t.PaymentDate.Year.Equals(date.Year) && t.PaymentDate.Month.Equals(date.Month));
            account.Transactions = newTransactions;

            await _bankAccountRepository.UpdateAccount(account.Id, account);

            return(newTransactions);
        }
コード例 #3
0
 private void GenerateCashFlowFromBank(BankAccountDoc account, Dictionary <string, Decimal> cashFlowIncomes, Dictionary <string, Decimal> cashFlowExpenses)
 {
     foreach (var transaction in account.Transactions.Where(t => t.PaymentDate.IsInLast6Months()))
     {
         var monthName = transaction.PaymentDate.ToString("MMM", CultureInfo.InvariantCulture);
         if (transaction.Type == TransactionType.Income)
         {
             cashFlowIncomes[monthName] += Math.Abs(transaction.Amount);
         }
         else if (transaction.Type == TransactionType.Expense)
         {
             cashFlowExpenses[monthName] += Math.Abs(transaction.Amount);
         }
     }
 }
コード例 #4
0
 private void GenerateNetWorthFromBank(BankAccountDoc account, Dictionary <string, Decimal> incomes, Dictionary <string, Decimal> expenses)
 {
     incomes.Add(account.Label, 0);
     expenses.Add(account.Label, 0);
     foreach (var transaction in account.Transactions.Where(t => t.PaymentDate.IsInThisMonth()))
     {
         if (transaction.Type == TransactionType.Income)
         {
             incomes[account.Label] += Math.Abs(transaction.Amount);
         }
         else if (transaction.Type == TransactionType.Expense)
         {
             expenses[account.Label] += Math.Abs(transaction.Amount);
         }
     }
 }
コード例 #5
0
        private int GenerateLoanFromBank(BankAccountDoc account, LoanOverviewDto loanOverview)
        {
            decimal principal = 0;
            decimal interest  = 0;

            foreach (var loan in account.Loans)
            {
                principal += loan.DeptAmount;
                interest  += loan.DeptAmount * loan.InterestRate / 100 *
                             (loan.NumberOfInterestPayments - loan.NextInterestPayment + 1) / 12;
            }

            loanOverview.Principal += principal;
            loanOverview.Interest  += interest;
            return(account.Loans.Count());
        }
コード例 #6
0
        public async Task <bool> UpdateAccount(String id, BankAccountDoc account)
        {
            try
            {
                account.UpdatedOn = DateTime.Now;
                ReplaceOneResult actionResult = await _context.BankAccounts.ReplaceOneAsync(a => a.Id.Equals(id),
                                                                                            account, new UpdateOptions { IsUpsert = true });

                return(actionResult.IsAcknowledged && actionResult.ModifiedCount > 0);
            }
            catch (Exception ex)
            {
                // log or manage the exception
                throw ex;
            }
        }
コード例 #7
0
        private int GenerateMortgageFromBank(BankAccountDoc account, LoanOverviewDto mortgageOverview)
        {
            decimal principal  = 0;
            decimal interest   = 0;
            decimal commission = 0;

            foreach (var mortgage in account.Mortgages)
            {
                principal  += mortgage.DeptAmount;
                interest   += mortgage.InterestAmount;
                commission += mortgage.PrepaymentCommission;
            }

            mortgageOverview.Principal  += principal;
            mortgageOverview.Interest   += interest;
            mortgageOverview.Commission += commission;

            return(account.Mortgages.Count());
        }