public void Eligibility_check_returns_value(bool verifierResult) { // Arrange var loanDecision = new LoanDecision(); var request = new CheckEligibility { LoanApplication = new LoanApplication(), LoanDecision = loanDecision, }; var mockEligibilityVerifier = new Mock <IEligibilityVerifier>(MockBehavior.Strict); mockEligibilityVerifier.Setup(m => m.IsEligible(It.IsNotNull <LoanApplication>())).Returns(verifierResult); var eligibilityCheck = new CheckEligibilityHandler(mockEligibilityVerifier.Object); // Act var response = eligibilityCheck.Handle(request); // Assert Assert.Equal(verifierResult, response.IsEligible); Assert.Equal(verifierResult, loanDecision.IsEligible); }
public ActionResult Create([Bind(Include = "Id, Number, Year, Date, DeductionStartDate, CersNumber, CersDate, Notes, LoanDecisionType, PaymentNumber, PaymentDate, IsPaidFromSalary, Reason, AdditionalClause, AdditionalIntroduction")] LoanDecision loanDecision) { Db db = new Db(DbServices.ConnectionString); if (ModelState.IsValid) { try { LoanDecisionServices.Insert(CurrentUser.Id, loanDecision, db); TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed"); return(RedirectToAction("Index")); } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; } catch (Exception ex) { TempData["Failure"] = ex.Message; } } ViewBag.LoanDecisionTypeList = new SelectList(LoanDecisionTypeServices.List(db), "Id", "Name"); return(View(loanDecision)); }
public void Affordability_check_returns_value(AffordabilityRating engineResult) { // Arrange var loanDecision = new LoanDecision(); var request = new CheckAffordability { LoanApplication = new LoanApplication(), LoanDecision = loanDecision, }; var mockAffordabilityVerifier = new Mock <IAffordabilityEngine>(MockBehavior.Strict); mockAffordabilityVerifier.Setup(m => m.Calculate(It.IsNotNull <LoanApplication>())).Returns(engineResult); var affordabilityCheck = new CheckAffordabilityHandler(mockAffordabilityVerifier.Object); // Act var response = affordabilityCheck.Handle(request); // Assert Assert.Equal(engineResult, response.AffordabilityRating); Assert.Equal(engineResult, loanDecision.AffordabilityRating); }
public Task <string> CreateLoanDecision(LoanDecision loanDecision) { loanDecision.Id = loanDecision.Id ?? Guid.NewGuid().ToString(); _loanDecisions.Add(loanDecision.Id, loanDecision); return(Task.FromResult(loanDecision.Id)); }
public Response ProcessMoveLoanToEmployee(List <SelectedLoans> loans, int oldEmployeeId, int newEmployeeId) { Db db = new Db(); Response response = new Cf.ViewModels.Response(); try { if (!(db.Connection.State == ConnectionState.Open)) { db.Connection.Open(); } db.Transaction = db.Connection.BeginTransaction(); // 1- Loan Decision LoanDecision loanDecision = new LoanDecision() { Date = System.DateTime.Now, Year = (short)System.DateTime.Now.Year, DeductionStartDate = System.DateTime.Now, LoanDecisionType = (int)LoanDecisionTypeEnum.ChangeSubscriber }; loanDecision = LoanDecisionServices.Insert(loanDecision); // 2- move loans foreach (SelectedLoans loan in loans) { if (loan.IsSelected) { List <EmployeeProductCalculatorResult> result = db.EmployeeProductCalculator(newEmployeeId, (short)loan.ProductTypeId, loan.RemainingAmount, (short)loan.RemainingPeriod); if (result.Count > 0) { db.LoanMoveFromEmployeeToEmployee(loan.LoanId, newEmployeeId, loanDecision.Id); } } } db.Transaction.Commit(); db.Connection.Close(); response.IsSuccess = true; } catch (CfException exc) { db.Transaction.Rollback(); db.Connection.Close(); response.IsSuccess = false; response.Messages.Add(exc.ErrorDefinition.LocalizedMessage); } catch (Exception exc) { db.Transaction.Rollback(); db.Connection.Close(); response.IsSuccess = false; response.Messages.Add(exc.Message); } return(response); }
public ActionResult CreateLoanRequestDecision(ManageLoanDecision model) { try { Db db = new Db(DbServices.ConnectionString); if (ModelState.IsValid) { try { int numberOfCheckedRequests = model.Requests.Where(c => c.isChecked).Count(); if (numberOfCheckedRequests != 0) { // 1- Add Loan Decision model.LoanDecision.LoanDecisionType = (int)LoanDecisionTypeEnum.Normal; if (model.LoanDecision.IsPaidFromSalary == null) { model.LoanDecision.IsPaidFromSalary = false; } LoanDecision instance = LoanDecisionServices.Insert(CurrentUser.Id, model.LoanDecision, db); // 2- Add Loans for (int i = 0; i < model.Requests.Count; i++) { if (!model.Requests[i].isChecked) { continue; } db.LoanGenerate(model.Requests[i].RequestId, instance.Id, (int)LoanGenerationStatusEnum.LoanRequest); } TempData["Success"] = ResourceServices.GetString(Cf.Data.Resources.ResourceBase.Culture, "UI", "InsertConfirmed"); } else { return(RedirectToAction("Index")); } } catch (CfException cfex) { TempData["Failure"] = cfex.ErrorDefinition.LocalizedMessage; } catch (Exception ex) { TempData["Failure"] = ex.Message; } } return(RedirectToAction("Index")); } catch { return(View()); } }
///<summary> /// Move Loan To Employee Method ///</summary> public void MoveLoanToEmployee(int userId, int LoanId, int EmployeeId, LoanDecision loanDecision) { try { Db db = new Db(DbServices.ConnectionString); // 0- Create Loan Decision LoanDecision decision = LoanDecisionServices.Insert(userId, loanDecision, db); // 1- Change the Status Of Old Loan to be Move To Employee Loan loan = LoanServices.Get(LoanId, db); loan.LoanStatus = (int)LoanStatusEnum.MoveToEmployee; LoanServices.Update(userId, loan, db); // 2- Process the Installments // 3- Create New Product + Refundable Product LoanRequest req = new LoanRequest() { //Request= }; Loan NewLoan = new Loan() { LoanDecision = decision.Id, Product = loan.Product, LoanGenerationStatus = (int)LoanGenerationStatusEnum.IncommingFromOtherSubscriber, LoanStatus = (int)LoanStatusEnum.Unfinished, LoanType = loan.LoanType }; LoanServices.Insert(userId, NewLoan); // 2- Add Loan and Generate Installment //db.LoanGenerate(model.Requests[i].RequestId, decision.Id, (int)LoanGenerationStatusEnum.LoanRequest); // 4- Generate Installment for the new Loan // } catch (Exception ex) { } }
// GET: LoanDecision/Delete/5 public ActionResult Delete(Nullable <int> id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } Db db = new Db(DbServices.ConnectionString); LoanDecision loanDecision = LoanDecisionServices.Get(id.Value, db); if (loanDecision == null) { return(HttpNotFound()); } return(View(loanDecision)); }
// GET: LoanDecision/Edit/5 public ActionResult Edit(Nullable <int> id) { Db db = new Db(DbServices.ConnectionString); if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } LoanDecision loanDecision = LoanDecisionServices.Get(id.Value, db); if (loanDecision == null) { return(HttpNotFound()); } ViewBag.LoanDecisionTypeList = new SelectList(LoanDecisionTypeServices.List(db), "Id", "Name", loanDecision.LoanDecisionType); return(View(loanDecision)); }
public async void Can_create_and_retrieve_loan_application() { // Arrange var loanDecision = new LoanDecision { Result = LoanDecisionResult.Accept }; var sut = new LoanDecisionRepository(); // Act var loanDecisionId = await sut.CreateLoanDecision(loanDecision); var retrievedLoanDecision = await sut.RetrieveLoanDecision(loanDecisionId); // Assert Assert.Equal(loanDecision.Result, retrievedLoanDecision.Result); }
public LoanDecision MakeDecision() { var decision = new LoanDecision(); if (_customerScore > 5) { decision.Approved = true; decision.InterestRate = 2.99M; } else if (_customerScore >= 3) { decision.Approved = true; decision.InterestRate = 4.99M; } else { decision.Approved = false; } return(decision); }
public async void Can_create_and_retrieve_loan_application_with_id() { // Arrange var loanDecision = new LoanDecision { Id = Guid.NewGuid().ToString(), Result = LoanDecisionResult.Accept }; var sut = new LoanDecisionRepository(); // Act var loanDecisionId = await sut.CreateLoanDecision(loanDecision); Assert.Equal(loanDecision.Id, loanDecisionId); var retrievedLoanDecision = await sut.RetrieveLoanDecision(loanDecisionId); // Assert Assert.Equal(loanDecision.Result, retrievedLoanDecision.Result); }
public Response ProcessMoveLoanToGuarantors(List <SelectedGuarantor> guarantors, int LoanId) { Db db = new Db(); Response response = new Cf.ViewModels.Response(); try { int numberOfGuarantors = guarantors.Where(c => c.IsSelected).ToList().Count; if (numberOfGuarantors == 0) { db.Transaction.Rollback(); db.Connection.Close(); response.IsSuccess = false; string message = "No Guarantors was selected"; response.Messages.Add(message); TempData["Failure"] = message; return(response); } if (!(db.Connection.State == ConnectionState.Open)) { db.Connection.Open(); } db.Transaction = db.Connection.BeginTransaction(); // 1- Loan Decision LoanDecision loanDecision = new LoanDecision() { Date = System.DateTime.Now, Year = (short)System.DateTime.Now.Year, DeductionStartDate = System.DateTime.Now, LoanDecisionType = (int)LoanDecisionTypeEnum.ChangeToGuarantor }; LoanDecision oldDecision = LoanDecisionServices.GetByNumber_YearFirstOrNull(loanDecision.Number, loanDecision.Year); if (oldDecision != null) { loanDecision.Number = (short)(loanDecision.Number + 1); } loanDecision = LoanDecisionServices.Insert(loanDecision); // 2- move loan to selected guarantors foreach (SelectedGuarantor guarantor in guarantors) { if (guarantor.IsSelected) { db.LoanMoveFromEmployeeToGuarantor(LoanId, guarantor.GuarantorId, loanDecision.Id, numberOfGuarantors); } } db.Transaction.Commit(); db.Connection.Close(); response.IsSuccess = true; } catch (CfException exc) { db.Transaction.Rollback(); db.Connection.Close(); response.IsSuccess = false; response.Messages.Add(exc.ErrorDefinition.LocalizedMessage); } catch (Exception exc) { db.Transaction.Rollback(); db.Connection.Close(); response.IsSuccess = false; response.Messages.Add(exc.Message); } return(response); }