public async Task <IActionResult> Create([FromBody] CreatePaymentMethodCommand command) { command.AccountId = User.GetUserId(); var response = await _mediator.Send(command); return(CreatedAt(response)); }
public void ShouldNotCreatePaymentMethod_When_CommandIsInvalid() { var command = new CreatePaymentMethodCommand("", "", "", Guid.NewGuid()); var handler = new CustomerCommandHandler(new CustomerRepositoryMock(), null); var result = handler.Handle(command); Assert.False(result.IsValid); }
public void ShouldCreatePaymentMethod_When_CommandIsValid() { var command = new CreatePaymentMethodCommand("James B", "1234 1234 1234 1234", "1234", Guid.NewGuid()); var handler = new CustomerCommandHandler(new CustomerRepositoryMock(), null); var result = handler.Handle(command); Assert.True(result.IsValid); }
public IActionResult Post(Guid customerId, [FromBody] CreatePaymentMethodCommand command) { var result = _handler.Handle(command, customerId); if (!result.IsValid) { return(BadRequest(result)); } return(Ok(result)); }
public async Task <IActionResult> Create([FromForm] CreatePaymentMethodCommand command) { if (ModelState.IsValid) { PaymentMethod taskReturn = await Mediator.Send(command); return(Ok(new PaymentMethodsResponse(nameof(PaymentMethod), taskReturn, taskReturn.statusCode, _baseLocalizer, _localizer))); } else { return(BadRequest(ModelState)); } }
public CommandResult Handle(CreatePaymentMethodCommand command) { var result = command.Validate(); var customer = _customerRepository.GetById(command.CustomerId); if (customer == null) { result.Messages.Add("Customer not found with the given Id"); return(result); } if (result.IsValid) { var paymentMethod = new PaymentMethod(Guid.NewGuid(), command.Alias, command.CardId, command.Last4); customer.AddPaymentMethod(paymentMethod); _customerRepository.Update(customer); result.Value = customer; } return(result); }
public CommandResult Handle(CreatePaymentMethodCommand command, Guid customerId) { command.CustomerId = customerId; return(Handle(command)); }