Exemplo n.º 1
0
        public ActionResult DeleteConfirmed(int id)
        {
            LoanBalanceEntry loanBalanceEntry = db.LoanBalanceEntries.Find(id);

            db.LoanBalanceEntries.Remove(loanBalanceEntry);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public ActionResult Edit([Bind(Include = "Id,Date,Amount,LoanId")] LoanBalanceEntry loanBalanceEntry)
 {
     if (ModelState.IsValid)
     {
         db.Entry(loanBalanceEntry).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.LoanId = new SelectList(db.Allocations, "Id", "Name", loanBalanceEntry.LoanId);
     return(View(loanBalanceEntry));
 }
Exemplo n.º 3
0
        // GET: LoanBalanceEntries/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LoanBalanceEntry loanBalanceEntry = db.LoanBalanceEntries.Find(id);

            if (loanBalanceEntry == null)
            {
                return(HttpNotFound());
            }
            return(View(loanBalanceEntry));
        }
Exemplo n.º 4
0
        // GET: LoanBalanceEntries/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            LoanBalanceEntry loanBalanceEntry = db.LoanBalanceEntries.Find(id);

            if (loanBalanceEntry == null)
            {
                return(HttpNotFound());
            }
            ViewBag.LoanId = new SelectList(db.Allocations, "Id", "Name", loanBalanceEntry.LoanId);
            return(View(loanBalanceEntry));
        }
Exemplo n.º 5
0
        private static Dictionary <int, decimal> GetLoanProjections(Loan loan)
        {
            PrimaryContext            db            = new PrimaryContext();
            Dictionary <int, decimal> retDictionary = new Dictionary <int, decimal>();

            //Check that loan entry is valid
            //bool valid = true;
            LoanBalanceEntry   balEntry = new LoanBalanceEntry();
            decimal            payment  = decimal.Zero;
            List <Transaction> transactionsResult;
            decimal            transactionsAmount = decimal.Zero;

            //Still need to select most recent entry
            if (db.LoanBalanceEntries.Any(x => x.LoanId == loan.Id))
            {
                balEntry = db.LoanBalanceEntries.First(x => x.LoanId == loan.Id);
            }
            if (db.Allocations.Any(x => x.Id == loan.Id))
            {
                payment = db.Allocations.First(x => x.Id == loan.Id).Amount;
            }
            if (db.Transactions.Any(x => x.AllocationId == loan.Id &&
                                    x.TransactionDate > balEntry.Date))
            {
                transactionsResult = db.Transactions.Where(x => x.AllocationId == loan.Id &&
                                                           x.TransactionDate > balEntry.Date).ToList();
                transactionsAmount = transactionsResult.AsQueryable().Sum(x => x.Amount);
            }

            //TODO: This section needs cleaned up
            //try
            //{
            //    balEntry = db.LoanBalanceEntries.First(x => x.LoanId == loan.Id);
            //}
            //catch (Exception e)
            //{
            //    throw new Exception("Invalid balance entry for loan:" + loan.Name + Environment.NewLine+ e.Message);
            //}
            //try
            //{
            //    payment = db.Allocations.First(x => x.Id == loan.Id).Amount;
            //}
            //catch (Exception e)
            //{
            //    throw new Exception("Invalid payment entry for loan:" + loan.Name + Environment.NewLine + e.Message);
            //}
            //try
            //{
            //    transactionsResult = db.Transactions.Where(x => x.AllocationId == loan.Id &&
            //                                                    x.TransactionDate > balEntry.Date).ToList();
            //    if(transactionsResult.Any()) transactionsAmount = transactionsResult.AsQueryable().Sum(x => x.Amount);
            //}
            //catch (Exception e)
            //{
            //    throw new Exception("Invalid transactions result for loan:" + loan.Name + Environment.NewLine + e.Message);
            //}
            //in future log exception and continue, use NoBalEntry method


            //Correct for time passed since entry = workingBal
            //________Diferent way of getting APR
            //TimeSpan span = new TimeSpan(System.DateTime.Now.Ticks - balEntry.Date.Ticks);
            //decimal interest = Decimal.Zero;
            //if(balEntry != null) Financial.GetMonthlyLoanInterest(balEntry.Amount, loan.Apr, (int)(span.Days / 30));

            //decimal initialBal = balEntry.Amount - transactionsAmount + interest;
            //decimal workingBal = initialBal;

            ////Current Month
            //retDictionary.Add(0,workingBal);

            ////For 6 months
            //for (int i = 1; i <= 6; i++)
            //{
            //    interest = Financial.GetMonthlyLoanInterest(workingBal, loan.Apr);
            //    //TODO: Change Events
            //    workingBal = workingBal - payment + interest;
            //    if (workingBal < 1) workingBal = 0;
            //    retDictionary.Add(i,workingBal);
            //}

            ////For 3 Years
            //workingBal = initialBal;
            //for (int i = 7; i <= 10; i++)
            //{
            //    interest = Financial.GetYearlyLoanInterest(workingBal, loan.Apr, payment);
            //    //TODO: Change Events
            //    workingBal = workingBal - payment * 12 + interest;
            //    if (workingBal < 1) workingBal = 0;
            //    retDictionary.Add(i, workingBal);
            //}

            return(retDictionary);
        }