public async Task <IActionResult> AddItem(Guid id, int quantity) { var product = await _productAppService.GetById(id); if (product == null) { return(BadRequest()); } if (product.StockQuantity < quantity) { TempData["Erro"] = "Product on stock insuficient"; return(RedirectToAction("ProductDetail", "ShopWindow", new { id })); } var command = new AddOrderItemCommand(ClientId, product.Id, product.Name, quantity, product.Value); await _mediatrHandler.SendCommand(command); if (ValidOperation()) { return(RedirectToAction("Index")); } TempData["Erros"] = GetErroMessage(); return(RedirectToAction("ProductDetail", "ShopWindow", new { id })); }
public async Task <IActionResult> AddOrderItem(Guid id, int productQuantity) { var product = await _productAppService.GetById(id); if (product == null) { return(BadRequest()); } if (product.StockQuantity < productQuantity) { TempData["Error"] = "Product with insufficient stock."; return(RedirectToAction("ProductDetails", "ShopWindow", new { id })); } var command = new AddOrderItemCommand(CustomerId, product.Id, product.Name, productQuantity, product.Price); await _mediatrHandler.SendCommand(command); if (IsOperationValid()) { return(RedirectToAction("Index")); } TempData["Errors"] = GetErrorMessages(); return(RedirectToAction("ProductDetails", "ShopWindow", new { id })); }
public async Task <IActionResult> Post([FromBody] ProductPostRequest request) { var productCommand = new RegisterProductCommand(request.Id, request.StockBalance, request.Name, request.Active); // await _mediator.Send(productCommand); var f = await _mediatorHandler.SendCommand(productCommand); return(Ok(f)); }
public async Task <IActionResult> Index() { var result = await _mediatrHandler.SendCommand(new RegisterClientCommand(Guid.NewGuid(), "Wallace Maia", "*****@*****.**", "13310731626")); return(CustomResponse(result)); }
public async Task Handle(OrderPaymentDeclinedEvent message, CancellationToken cancellationToken) { await _mediatrHandler.SendCommand(new CancelOrderProcessingAndSupplyStockCommand(message.CustomerId, message.OrderId)); }
public async Task Handle(OrderStockRejectedEvent message, CancellationToken cancellationToken) { // cancel payment order - return error for client await _mediatorHandler.SendCommand(new CancelProcessingOrderCommand(message.OrderId, message.ClientId)); }
public async Task Handle(InsufficientStockForOrderEvent message, CancellationToken cancellationToken) { await _mediatrHandler.SendCommand(new CancelOrderProcessingCommand(message.CustomerId, message.OrderId)); }
public async Task Handle(PaidOrderEvent message, CancellationToken cancellationToken) { await _mediatrHandler.SendCommand(new FinishOrderCommand(message.CustomerId, message.OrderId)); }