示例#1
0
        public async Task <ActionResult> GetCreditUnion(int id)
        {
            try
            {
                if (await _repo.GetCreditUnionById(id) is CoreCreditUnion union)
                {
                    var transformed = ApiMapper.MapUnion(union);

                    return(Ok(transformed));
                }
            }
            catch (NullReferenceException)
            {
                return(NotFound($"No credit union with the id of {id}."));
            }

            return(NotFound("There is no Credit Union by that Id."));
        }
示例#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!"));
        }