Пример #1
0
        //GET: Loan/CreateLoan
        //  Loan/CreateLoanCalc?degreeId=2&schoolId=5
        public async Task <ActionResult> CreateLoanCalc(int degreeId, int schoolId)
        {
            var user = await GetCurrentUserAsync();

            var Degreeschool = await _context.DegreeSchool
                               .Include(ds => ds.Degree)
                               .Include(ds => ds.School)
                               .FirstOrDefaultAsync(ds => ds.DegreeId == degreeId && ds.SchoolId == schoolId);

            var totalSchoolCost        = Degreeschool.TotalCost;
            var degreeName             = Degreeschool.Degree.EducationName;
            var schoolName             = Degreeschool.School.SchoolName;
            var degreesSchoolId        = Degreeschool.Id;
            var LoanWorkbenchViewModel = new LoanWorkbenchViewModel()
            {
                SchoolId        = schoolId,
                DegreeId        = degreeId,
                TotalSchoolCost = totalSchoolCost,
                DegreeName      = degreeName,
                SchoolName      = schoolName,
                DegreeSchoolId  = degreesSchoolId,
            };

            return(View(LoanWorkbenchViewModel));
        }
Пример #2
0
        public async Task <IActionResult> CreateLoanCalc(int degreeId, int schoolId, LoanWorkbenchViewModel loanViewModel)

        {
            try
            {
                var user = await GetCurrentUserAsync();

                var Degreeschool = await _context.DegreeSchool
                                   .Include(ds => ds.Degree)
                                   .Include(ds => ds.School)
                                   .FirstOrDefaultAsync(ds => ds.DegreeId == loanViewModel.DegreeId && ds.SchoolId == loanViewModel.SchoolId);


                var totalSchoolCost      = Degreeschool.TotalCost;
                var futureCareerEarnings = (Degreeschool.Degree.EarningAvg * 20);

                // Define variables to help calculate the loan payments
                var loanAmount                 = (totalSchoolCost - (loanViewModel.CashPaid + loanViewModel.Grants + loanViewModel.Scholarships));
                var rateOfInterest             = (loanViewModel.LoanRate / 100) / 12;
                var numberOfPayments           = loanViewModel.LoanLengthYears * 12;
                var loanPayment                = (loanAmount * rateOfInterest) / (1 - Math.Pow(1 + rateOfInterest, numberOfPayments * -1));
                var totalLoanPayments          = loanPayment * numberOfPayments;
                var totalCashGrantScholarships = loanViewModel.CashPaid + loanViewModel.Grants + loanViewModel.Scholarships;
                var totalAmountPaid            = totalLoanPayments + totalCashGrantScholarships;
                var benefitCostRatio           = futureCareerEarnings / totalAmountPaid;
                var loan = new Loan()


                {
                    FutureCareerEarnings = futureCareerEarnings,
                    TotalSchoolCost      = totalSchoolCost,
                    CashPaid             = loanViewModel.CashPaid,
                    Grants                   = loanViewModel.Grants,
                    Scholarships             = loanViewModel.Scholarships,
                    LoanAmount               = loanAmount,
                    LoanRate                 = loanViewModel.LoanRate,
                    LoanLengthYears          = loanViewModel.LoanLengthYears,
                    LoanLengthMonths         = loanViewModel.LoanLengthYears * 12,
                    LoanPayment              = loanPayment,
                    FinWorkBenchStep         = loanViewModel.FinWorkBenchStep,
                    ApplicationUserId        = user.Id,
                    DegreeSchoolId           = Degreeschool.Id,
                    TotalLoanPayments        = totalLoanPayments,
                    TotalAmountPaid          = totalAmountPaid,
                    BenefitCostAnalysisRatio = Convert.ToInt32(benefitCostRatio)
                };

                _context.Loan.Add(loan);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(BCAIndex)));
            }
            catch (Exception ex)
            {
                return(View());
            }
        }
Пример #3
0
        //GET: Loan/CreateLoan
        public ActionResult CreateLoan(int degreeId, int schoolId)
        {
            var LoanWorkbenchViewModel = new LoanWorkbenchViewModel()
            {
                SchoolId = schoolId,
                DegreeId = degreeId
            };

            return(View(LoanWorkbenchViewModel));
        }
Пример #4
0
        // GET: Loan/Edit/5
        // This the Add Notes Update Notes
        public async Task <ActionResult> Edit(int id)
        {
            var user = await GetCurrentUserAsync();

            var viewModel = new LoanWorkbenchViewModel();
            var loan      = await _context.Loan.FirstOrDefaultAsync(l => l.Id == id);

            if (loan.ApplicationUserId != user.Id)
            {
                return(NotFound());
            }


            return(View(viewModel));
        }