public class CustomerOrdersController : Controller { private readonly IMediator _mediator;
public CustomerOrdersController(IMediator mediator) { this._mediator = mediator; }
/// <summary> /// Add customer order. /// </summary> /// <param name="customerId">Customer ID.</param> /// <param name="request">Products list.</param> [Route("{customerId}/orders")] [HttpPost] [ProducesResponseType((int)HttpStatusCode.Created)] public async Task<IActionResult> AddCustomerOrder( [FromRoute]Guid customerId, [FromBody]CustomerOrderRequest request) { await _mediator.Send(new AddCustomerOrderCommand(customerId, request.Products));
return Created(string.Empty, null); } }
public class AddCustomerOrderCommandHandler : IRequestHandler<AddCustomerOrderCommand> { private readonly ICustomerRepository _customerRepository; private readonly IProductRepository _productRepository; private readonly IForeignExchange _foreignExchange;
public AddCustomerOrderCommandHandler( ICustomerRepository customerRepository, IProductRepository productRepository, IForeignExchange foreignExchange) { this._customerRepository = customerRepository; this._productRepository = productRepository; this._foreignExchange = foreignExchange; }
public async Task<Unit> Handle(AddCustomerOrderCommand request, CancellationToken cancellationToken) { // handling... } }
|