Example #1
0
        public async Task <IActionResult> CreateLoan([FromBody] CreateLoanRequestModel createLoanRequestModel)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var loanResult = await _loanService.CreateLoanAsync(createLoanRequestModel);

                if (loanResult.HasErrors())
                {
                    return(BadRequest(loanResult.ValidationErrors));
                }

                return(CreatedAtAction(nameof(GetLoanById), new { id = loanResult.LoanDto.LoanId }, loanResult.LoanDto));
            }
            catch (ValidationException validationException)
            {
                return(StatusCode(500, validationException.Message));
            }
        }
Example #2
0
        public async Task <ActionResult <Guid> > CreateLoanAsync(LoanCreateModel model)
        {
            var createLoanResponseModel = await _loanService.CreateLoanAsync(model);

            return(Ok(createLoanResponseModel));
        }