private void Save()
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         _context.Add(this);
         _context.SaveChanges();
     }
 }
 /// <summary>
 /// Saves the current Simulation
 /// </summary>
 private string Save()
 {
     using (FinPlannerContext _context = new FinPlannerContext())
     {
         if (this.SimulationId == "temp")
         {
             this.SimulationId = Guid.NewGuid().ToString();
             _context.Add(this.SimulationAssumptions);
             _context.Add(this);
         }
         else
         {
             _context.Entry(this).State = EntityState.Modified;
         }
         //_context.SaveChanges();
     }
     return(this.SimulationId);
 }
Exemple #3
0
        public async Task <bool> UpdateAccounts(string collectionsId, List <Account> accounts)
        {
            YodleeAccountModel        model          = new YodleeAccountModel();
            List <YodleeAccountLevel> yodleeAccounts = await model.GetYodleeAccounts(collectionsId);

            try
            {
                using (FinPlannerContext _context = new FinPlannerContext())
                {
                    foreach (Account item in accounts)
                    {
                        if (item.YodleeId == 0 && item.AccountIdentifier != null)
                        {
                            item.YodleeId = yodleeAccounts.Where(x => x.accountNumber == item.AccountIdentifier).Select(x => x.id).FirstOrDefault();
                        }
                        else
                        {
                            YodleeAccountLevel accountLevel = yodleeAccounts.Where(x => x.accountNumber == item.AccountIdentifier).FirstOrDefault();
                            if (accountLevel != null)
                            {
                                if (accountLevel.availableBalance != null)
                                {
                                    item.Available = accountLevel.availableBalance.amount;
                                }
                                else if (accountLevel.availableCredit != null)
                                {
                                    item.Available = accountLevel.availableCredit.amount;
                                }
                                else
                                {
                                    item.Available = accountLevel.balance.amount;
                                }
                            }
                        }
                        _context.Entry(item).State = EntityState.Modified;
                        AccountBalance balance = new AccountBalance()
                        {
                            AccountBalanceId = Guid.NewGuid().ToString(),
                            AccountId        = item.Id,
                            Amount           = item.Available,
                            Date             = DateTime.Now.Date
                        };
                        _context.Add(balance);
                    }

                    _context.SaveChanges();
                }
                return(true);
            }
            catch (Exception e)
            {
                ExceptionCatcher catcher = new ExceptionCatcher();
                catcher.Catch(e.Message);
                return(false);
            }
        }
 public void BankCharges(Collections collection)
 {
     try
     {
         Budget budget = collection.Budgets.Where(x => x.Simulation == false).OrderByDescending(x => x.EndDate).First();
         double fees   = 0;
         foreach (Account acc in collection.Accounts.Where(x => x.AccountType.Transactional == true))
         {
             fees = fees + acc.MonthlyFee;
             double debt = acc.AccountLimit - acc.Available;
             if (debt > 0)
             {
                 fees = fees + debt * (acc.CreditRate / 12 / 100);
             }
         }
         fees = Math.Round(fees, 2);
         budget.GetBudgetTransacions();
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             if (budget.BudgetTransactions.Where(x => x.CFType.Name == "Bank Charges" && x.Automated == true).Any())
             {
                 BudgetTransaction transaction = budget.BudgetTransactions.Where(x => x.CFType.Name == "Bank Charges" && x.Automated == true).FirstOrDefault();
                 transaction.Amount = fees;
                 _context.Entry(transaction).State = EntityState.Modified;
             }
             else
             {
                 CFClassification  classification = new CFClassification("Expense");
                 CFType            type           = new CFType("Bank Charges");
                 BudgetTransaction transaction    = new BudgetTransaction()
                 {
                     BudgetId            = budget.BudgetId,
                     Automated           = true,
                     BudgetTransactionId = Guid.NewGuid().ToString(),
                     CFClassificationId  = classification.Id,
                     CFTypeId            = type.Id,
                     Name   = "Automated Bank Charges",
                     Amount = fees,
                 };
                 _context.Add(transaction);
             }
             _context.SaveChanges();
         }
     }
     catch (Exception e)
     {
         ExceptionCatcher catcher = new ExceptionCatcher();
         catcher.Catch(e.Message);
     }
 }
 public void Update(Account account)
 {
     if (isExists(account.Id))
     {
     }
     else
     {
         AccountAmortisation amortisation = new AccountAmortisation()
         {
             AccountId             = account.Id,
             AccountAmortisationId = Guid.NewGuid().ToString()
         };
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             _context.Add(amortisation);
             try
             {
                 _context.SaveChanges();
             }
             catch (Exception e)
             {
                 ExceptionCatcher catcher = new ExceptionCatcher();
                 catcher.Catch(e.Message);
             }
         }
         PaymentModel payment = new PaymentModel(account, amortisation.AccountAmortisationId);
         using (FinPlannerContext _context = new FinPlannerContext())
         {
             _context.Add(payment);
             try
             {
                 _context.SaveChanges();
             }
             catch (Exception e)
             {
                 ExceptionCatcher catcher = new ExceptionCatcher();
                 catcher.Catch(e.Message);
             }
         }
         MonthlyAmortisation monthly = new MonthlyAmortisation();
         monthly.Create(account, payment, amortisation);
     }
 }
Exemple #6
0
        public ReturnModel Save()
        {
            ManualCashFlow flow        = new ManualCashFlow(this);
            ReturnModel    returnModel = new ReturnModel();

            using (FinPlannerContext _context = new FinPlannerContext())
            {
                _context.Add(flow);
                try
                {
                    _context.SaveChanges();
                    AccountChange change = new AccountChange();
                    change.AddAccountChange(flow);
                    returnModel.result = true;
                    return(returnModel);
                }
                catch (Exception e)
                {
                    returnModel.returnStr = e.Message;
                    returnModel.result    = false;
                    return(returnModel);
                }
            }
        }