public async Task UpdateLoanAsync(CoreLoan loan) { var newLoan = Mapper.MapLoan(loan); _context.Entry(newLoan).State = EntityState.Modified; await Save(); }
public async Task <CoreLoan> AddLoanAsync(CoreLoan loan) { var newLoan = Mapper.MapLoan(loan); _context.Loan.Add(newLoan); await Save(); return(Mapper.MapLoan(newLoan)); }
/* ************************ * * * * * Loans * * * * * ************************ */ public static Loan MapLoan(CoreLoan loan) { return(new Loan { LoanId = loan.LoanId, Deposit = loan.Deposit, MonthlyAmountDue = loan.MonthlyAmountDue, PaymentDueDate = loan.PaymentDueDate, TotalAmountDue = loan.TotalAmountDue, UserId = loan.User.UserId, UnionId = loan.Union.UnionId }); }
public void MapLoan_StateUnderTest_ExpectedBehavior1() { var mapper = this.CreateMapper(); CoreLoan loan = new CoreLoan { AccumulatedCost = 1, Id = 1, InterestRate = 1, MonthlyRate = 1, RetainingCost = 1, UserId = 1 }; var result = Mapper.MapLoan( loan); Assert.True(true); }
public void MapLoanApi_StateUnderTest_ExpectedBehavior() { var apiMapper = this.CreateApiMapper(); CoreLoan loan = new CoreLoan { AccumulatedCost = 1, Id = 1, InterestRate = 1, MonthlyRate = 1, RetainingCost = 1, UserId = 1 }; var result = ApiMapper.MapLoanApi( loan); Assert.True(true); this.mockRepository.VerifyAll(); }
/* ************************ * * * * * Loans * * * * * ************************ */ public static ApiLoan MapLoan(CoreLoan loan) { return(new ApiLoan { LoanId = loan.LoanId, Deposit = loan.Deposit, MonthlyAmountDue = loan.MonthlyAmountDue, PaymentDueDate = loan.PaymentDueDate, TotalAmountDue = loan.TotalAmountDue, UserId = loan.User.UserId, UserFirstName = loan.User.FirstName, UserLastName = loan.User.LastName, UnionId = loan.Union.UnionId, CreditUnionName = loan.Union.CreditUnionName }); }
public async Task <ActionResult> PostLoan(ApiLoan loan) { try { var resource = new CoreLoan { LoanId = loan.LoanId, Deposit = loan.Deposit, MonthlyAmountDue = loan.MonthlyAmountDue, PaymentDueDate = loan.PaymentDueDate, TotalAmountDue = loan.TotalAmountDue, User = (await _userRepo.GetUserById(loan.UserId)), Union = (await _unionRepo.GetCreditUnionById(loan.UnionId)) }; await _repo.AddLoanAsync(resource); return(Ok("Loan added!")); } catch (Exception e) { return(BadRequest($"Error! {e.Message}")); } }
public async Task <IActionResult> PutLoan(int id, ApiLoan loan) { if (id != loan.LoanId) { return(BadRequest("Loan does not exist.")); } var resource = new CoreLoan { LoanId = loan.LoanId, Deposit = loan.Deposit, MonthlyAmountDue = loan.MonthlyAmountDue, PaymentDueDate = loan.PaymentDueDate, TotalAmountDue = loan.TotalAmountDue, User = (await _userRepo.GetUserById(loan.UserId)), Union = (await _unionRepo.GetCreditUnionById(loan.UnionId)) }; try { await _repo.UpdateLoanAsync(resource); } catch (DbUpdateConcurrencyException) { if (!await _repo.LoanExistAsync(id)) { return(NotFound("Loan not found.")); } else { throw; } } return(Ok("Loan updated!")); }