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.")); } }
public async Task <IActionResult> CreateLoan(CreateLoanCommand command) { try { var response = await Mediator.Send(command); if (response.HasRequestError) { ViewBag.Status = new Status { Type = Type.danger, Message = response.ErrorMessage }; return(View()); } } catch (ValidationException e) { ModelState.AddValidationErrors(e); return(View()); } ViewBag.Status = new Status { Type = Type.success, Message = "Loan was successfully created" }; return(View()); }
public ActionResult CreateLoan(int id) { var model = new CreateLoanCommand() { UserId = id }; return(View(model)); }
public async Task <ActionResult <BaseResponse <CreateLoanDto> > > Create(CreateLoanCommand request) { var result = await _mediator.Send(request); if (!result.Success) { return(BadRequest(result)); } return(result); }
public LoanLimitTests() { _copyRepo = new Mock <ICopyRepository>(); _loanHelper = new Mock <ILoanHelper>(); _loanRepo = new Mock <ILoanRepository>(); _command = new Mock <CreateLoanCommand>().Object; _context = new Mock <IGTLContext>(); _uow = new Mock <IUnitOfWork>(); _fakeCopy = new Mock <Copy>().Object; }
public async Task <IActionResult> CreateAsync([FromBody] CreateLoanCommand createLoanCommand) { var validationResult = await commandBus.Validate(createLoanCommand); if (!validationResult.IsValid) { return(BadRequest(validationResult)); } await commandBus.Submit(createLoanCommand); return(Created($"users/{createLoanCommand.Id}", createLoanCommand)); }
public CreateLoanCommand ToCommand() { var customerContact = new CustomerContact(CustomerName, PreferredPhoneNumber, AlternatePhoneNumber, PostalAddress); var bankAccount = new BankAccount(BankBsb, BankAccount); var duration = new Duration(12, DurationUnit.Month); var command = new CreateLoanCommand(Guid.NewGuid(), Guid.NewGuid(), DateTimeOffset.Now, customerContact, bankAccount, PaymentPlan.Weekly, LoanAmount, duration); return(command); }
public void Create(CreateLoanCommand command) { if (Version > 0) { throw new InvalidOperationException("Loan already created."); } if (command.Amount < 50m || 2000 < command.Amount) { throw new InvalidOperationException("Only loan amounts between $50.00 and $2000.00 are supported."); } if (!IsUnder2Years(command.Term)) { throw new InvalidOperationException("Only loan terms up to 2 years are supported."); } AddEvent(new LoanCreatedEvent(command.CreatedOn, command.Amount, command.Term, command.PaymentPlan)); AddEvent(new LoanCustomerContactChangedEvent(command.CustomerContact.Name, command.CustomerContact.PreferredPhoneNumber, command.CustomerContact.AlternatePhoneNumber, command.CustomerContact.PostalAddress)); AddEvent(new LoanBankAccountChangedEvent(command.BankAccount.Bsb, command.BankAccount.AccountNumber)); }
public async Task TDS_1_TC2_5() { // Arrange var command = new CreateLoanCommand { LoanerCardBarcode = 10000, CopyBarcode = 100001, LibraryName = "Georgia Tech Library" }; // Act var response = await _mediator.Send(command); Loan insertedLoan; // Assert var query = $"SELECT * FROM Loan WHERE Id = {response.SubjectId}"; using (var cmd = _context.CreateCommand()) { insertedLoan = cmd.Connection.QuerySingle <Loan>(query); } Assert.NotNull(insertedLoan); }
public async Task <IActionResult> CreateLoan(CreateLoanCommand command) { return(Ok(await Mediator.Send(command))); }
public CommandResult CreateLoan(CreateLoanCommand command) { var handler = new LoanCommandHandler(); return(handler.Handle(command)); }
public ActionResult CreateLoan(CreateLoanCommand command) { client.CreateLoan(command); return(View()); }
public async Task <ActionResult> Post([FromBody] CreateLoanCommand request) { var result = await _mediator.Send(request); return(new JsonResult(result)); }
public async Task <ActionResult <OperationResult> > SaveAsync([Required][FromBody] CreateLoanCommand command, CancellationToken cancellationToken = default) => Ok(await Mediator.Send(command, cancellationToken));