Exemple #1
0
        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}"));
            }
        }
Exemple #2
0
        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!"));
        }