public async Task <BaseResponse <CreateLoanDto> > Handle(CreateLoanCommand request, CancellationToken cancellationToken) { try { var loan = new Loan(request.NumberOfInstallments, request.Interest, request.Amount, request.PersonId); var loanId = await _loanRepository.CreateLoanAsync(loan); var loanWithPayments = await _loanService.CalculatePayments(loan); var paymentDtos = _mapper.Map <IEnumerable <PaymentDto> >(loanWithPayments.Payments); var loanCost = _loanService.CalculateLoanCost(loan); return(new BaseResponse <CreateLoanDto>(new CreateLoanDto() { Id = loanId, Payments = paymentDtos, TotalCost = loanCost })); } catch (Exception e) { // there should be logging return(new BaseResponse <CreateLoanDto>("An error occurred when handling request.")); } }