Esempio n. 1
0
        public decimal StudentLoanRepaymentAmount(StudentLoan studentLoan, decimal totalAmount)
        {
            if (studentLoan == StudentLoan.Yes)
            {
                if (totalAmount > 1750 && totalAmount < 2000)
                {
                    studentLoanRepaymentAmount = 15m;
                }
                else if (totalAmount >= 2000 && totalAmount < 2250)
                {
                    studentLoanRepaymentAmount = 38m;
                }
                else if (totalAmount >= 2250 && totalAmount < 2500)
                {
                    studentLoanRepaymentAmount = 60m;
                }
                else if (totalAmount >= 2500)
                {
                    studentLoanRepaymentAmount = 83m;
                }
                else
                {
                    studentLoanRepaymentAmount = 0;
                }
            }
            else
            {
                studentLoanRepaymentAmount = 0;
            }

            return(studentLoanRepaymentAmount);
        }
        public ActionResult SaveLoanValues(StudentLoan studentLoan)
        {
            //capturing posted data from client (controller/server)

            /*var education = studentLoan.EducationProgramData;
             * var minorProfile = studentLoan.MinorProfile;
             * var guarantors = studentLoan.Guarantors;
             * var applicant = studentLoan.LoanApplicantProfile;
             * var loanConfig = studentLoan.LoanConfig;*/
            if (!ModelState.IsValid)
            {
                String messages = String.Join(Environment.NewLine, ModelState.Values.SelectMany(v => v.Errors)
                                              .Select(v => v.ErrorMessage + " " + v.Exception));
                return(Content(messages));
            }

            var resultViewModel = ProcessStudentLoanForDbEntry(studentLoan);

            //Determine whether posted customers are sent with id. Further eliminate the information since the customer already exists

            //validate values with respect to constraints on the mapped DPAC fields
            //As discussed prior to development, validation should not be thorough as this was to supposedly be done by the student portal development team

            //Throw an exception should validation fail and alert client

            //commence mapping should validity not be compromised

            //save data via db context

            //Notify client of successful operation


            return(View("SuccessPageReport", resultViewModel));
        }
Esempio n. 3
0
        /*
         * Method name: submitButton_Click
         * Version: #1.0
         * Author: Michael Fesser
         * Description: This method accpets the values from the form and creates the loan and studentLoan objects.
         * Outputs: anualInterest, totalInterestCharge, totalLoan.
         * Returns: None.
         * Change History: None.
         */
        private void submitButton_Click(object sender, EventArgs e)
        {
            int     error      = 0;
            decimal loanAmount = 0;

            try
            {
                loanAmount = Decimal.Parse(loanAmountTB.Text);
            }
            catch (Exception err)
            {
                MessageBox.Show("You need to enter a number");
                error = 1;
                loanAmountTB.Clear();
                loanAmountTB.Focus();
            }

            if (error == 0)
            {
                // Check to see if it is a student loan.
                if (studentRB.Checked == true)
                {
                    // Create object and pass values to the constructor.
                    StudentLoan studentLoan = new StudentLoan(lastNameTB.Text, firstNameTB.Text, emailTB.Text, studentRB.Checked, loanAmount, loanLengthNUD.Value);
                    studentLoan.calculate();
                    // Output
                    annualInterestTB.Text = studentLoan.anualInterest.ToString("c");
                    totalInterestTB.Text  = studentLoan.totalInterestCharge.ToString("c");
                    loanTotalTB.Text      = studentLoan.totalLoan.ToString("c");
                }
                else
                {
                    // Create object and pass values to the constructor.
                    Loan loan = new Loan(lastNameTB.Text, firstNameTB.Text, emailTB.Text, homeRB.Checked, autoRB.Checked, loanAmount, loanLengthNUD.Value);
                    loan.calculate();
                    // Output
                    annualInterestTB.Text = loan.anualInterest.ToString("c");
                    totalInterestTB.Text  = loan.totalInterestCharge.ToString("c");
                    loanTotalTB.Text      = loan.totalLoan.ToString("c");
                }
            }
        }
        public ActionResult JsonFileData(HttpPostedFileBase myFile)
        {
            //return this.Json(new { data = 21, success = true, message = $"" }, JsonRequestBehavior.AllowGet);
            var loan = new StudentLoan();


            //file type should be 'application/json'
            string fileName = myFile.FileName;

            if (myFile != null && myFile.ContentLength > 0)
            {
                var userList = new List <fuserid>();
                // get contents to string
                string str = (new StreamReader(myFile.InputStream)).ReadToEnd();
                using (var dpac = new DPACEntities())
                {
                    userList = dpac.fuserids.Where(u => u.accs_code == "CDST" || u.accs_code == "EUCO" && u.enabled == true).ToList();
                    // deserializes string into object
                }

                try
                {
                    loan = JsonConvert.DeserializeObject <StudentLoan>(str);
                    loan.LoanConfig.UserIds = userList;
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    //return Json(new { success = false, message = $"Error thrown in DB: {e.Message}" });
                    //Console.WriteLine(e);
                }
            }

            /*var viewModel = new StudentLoanViewModel()
             * {
             *  StudentLoan = loan
             * };*/
            //return Json(new { success = true, partialStuff = PartialView("_JsonLoanData", loan), message = $"Edsf" });
            return(PartialView("_JsonLoanData", loan));
        }
        public LoanInsertionResult ProcessStudentLoanForDbEntry(StudentLoan loan)
        {
            string        minorId = null;
            string        applicantId;
            List <string> guarantorIds = new List <string>();

            string LoanApplicationId;

            //result container
            CustomerEntityValidator        loanApplicantResult = new CustomerEntityValidator();
            CustomerEntityValidator        minorProfileResult  = new CustomerEntityValidator();
            List <CustomerEntityValidator> guarantorResults    = new List <CustomerEntityValidator>();


            var  loanConfigResult          = new Application();
            var  studentDataResult         = new Application();
            bool crossReferenceMinorResult = false;

            IList <bool> crossReferenceGuarantorResults = new List <bool>();

            //Loan applicant Operations
            if (loan.LoanApplicantProfile.ApplicantId == null)
            {
                var appId = new CustomerDbHandler(loan.LoanApplicantProfile.CustomersFirstname, loan.LoanApplicantProfile.CustomersLastname, loan.LoanApplicantProfile.CustomersMiddlename);
                appId.CreateCustomerId();
                // string id = appId.CustomerId;
                loanApplicantResult = SaveLoanApplicant(loan.LoanApplicantProfile, appId.CustomerId, appId.ParsedName);

                applicantId = null;
            }
            else
            {
                applicantId = (ValidateCustomerPostId(loan.LoanApplicantProfile.ApplicantId))? loan.LoanApplicantProfile.ApplicantId.ToUpper() : null;
                loanApplicantResult.CustomerId = (applicantId != null) ? applicantId : null;
                loanApplicantResult.Customer   = (applicantId != null) ? true : false;
                //simply discards the posted info and retains the given ID, also run further validation on Id
            }

            //Minor profile operations
            if (loan.MinorProfile != null)
            {
                if (loan.MinorProfile.MinorId == null)
                {
                    var minorCustomer = new CustomerDbHandler(loan.MinorProfile.CustomersFirstname, loan.MinorProfile.CustomersLastname, loan.MinorProfile.CustomersMiddlename);
                    minorCustomer.CreateCustomerId();

                    minorProfileResult = SaveMinorProfile(loan.MinorProfile, minorCustomer.CustomerId, minorCustomer.ParsedName);
                }
                else
                {
                    minorId = (ValidateCustomerPostId(loan.MinorProfile.MinorId)) ? loan.MinorProfile.MinorId.ToUpper() : null;
                    minorProfileResult.CustomerId = (minorId != null)? minorId : null;
                    minorProfileResult.Customer   = (minorId != null) ? true : false;
                }
            }


            //Guarantor Operations
            if (loan.Guarantors != null)
            {
                foreach (var guarantor in loan.Guarantors)
                {
                    if (guarantor.ApplicantId == null)
                    {
                        var g = new CustomerDbHandler(guarantor.GuarantorPersonal.CustomersFirstname, guarantor.GuarantorPersonal.CustomersLastname, guarantor.GuarantorPersonal.CustomersMiddlename);
                        g.CreateCustomerId();

                        guarantorResults.Add(SaveGuarantor(guarantor, g.CustomerId, g.ParsedName));
                    }
                    else
                    {
                        if (ValidateCustomerPostId(guarantor.ApplicantId.ToUpper()))
                        {
                            guarantorIds.Add(guarantor.ApplicantId.ToUpper());
                            guarantorResults.Add(new CustomerEntityValidator()
                            {
                                CustomerId          = guarantor.ApplicantId.ToUpper(),
                                Customer            = true,
                                IsExistingGuarantor = true,
                            });
                        }
                    }
                }
            }

            //Loan configuration operations
            if (loan.LoanConfig != null)
            {
                string globAppId;
                var    application = new Application();
                if (application.CreateApplicationId())
                {
                    if (string.IsNullOrEmpty(applicantId))
                    {
                        LoanApplicationId = application.ApplicationId;

                        loanConfigResult = SaveLoanConfiguration(loan.LoanConfig, LoanApplicationId, loanApplicantResult.CustomerId, loan.LoanConfig.OfficerId);
                    }
                    else
                    {
                        loanConfigResult = SaveLoanConfiguration(loan.LoanConfig, application.ApplicationId, applicantId, loan.LoanConfig.OfficerId);
                        //  globAppId = loanConfigResult.ApplicationId;
                    }
                }



                //Education Program Data operations
                if (loan.EducationProgramData != null && loanConfigResult.ApplicationSuccess)
                {
                    studentDataResult = SaveEducationProgramData(loan.EducationProgramData, loanConfigResult.ApplicationId, applicantId);
                }
            }

            //Finally, linking the entities into a relational model
            if (minorId == null && loanConfigResult.ApplicationSuccess)
            {
                if (minorProfileResult.Customer && loanConfigResult.ApplicationSuccess)
                {
                    crossReferenceMinorResult = CrossReferenceEntity(minorProfileResult.CustomerId, "S", loanConfigResult.ApplicationId);
                }
            }
            else
            {
                crossReferenceMinorResult = CrossReferenceEntity(minorId, "S", loanConfigResult.ApplicationId);
            }

            if (loanConfigResult.ApplicationSuccess)
            {
                foreach (var guarantorRes in guarantorResults)
                {
                    if (guarantorRes.Customer && !(guarantorRes.IsExistingGuarantor))
                    {
                        crossReferenceGuarantorResults.Add(CrossReferenceEntity(guarantorRes.CustomerId, "G", loanConfigResult.ApplicationId));
                    }
                }

                if (guarantorIds.Any())
                {
                    foreach (var g in guarantorIds)
                    {
                        crossReferenceGuarantorResults.Add(CrossReferenceEntity(g, "G", loanConfigResult.ApplicationId));
                    }
                }
            }

            return(new LoanInsertionResult()
            {
                Applicant = loanApplicantResult,
                Minor = minorProfileResult,
                Guarantors = guarantorResults,

                LoanApplication = loanConfigResult,
                StudentInformation = studentDataResult,

                CrossReferenceOperation = crossReferenceMinorResult,
                CrossRefGuarantorOperation = crossReferenceGuarantorResults
            });
        }