public async Task <IActionResult> Delete(Guid cartId, [FromBody] RemoveItemRequest request) { var validationResult = new RemoveItemValidator().Validate(request); if (!validationResult.IsValid) { return(BadRequest(validationResult.Errors)); } var cart = await service.GetCart(cartId); if (cart == null) { return(NotFound()); } await service.RemoveItemFromCart(cartId, request); return(NoContent()); }
public async Task <IActionResult> RemoveItem(string basketId, [FromBody] RemoveItemRequest request) { var validation = new RemoveItemValidator().Validate(request); if (!validation.IsValid) { return(BadRequest(validation.Errors)); } var basketReadModel = await queryProcessor.ProcessAsync(new ReadModelByIdQuery <BasketReadModel>(basketId), CancellationToken.None); if (basketReadModel == null) { return(NotFound()); } try { var task = await commandBus.PublishAsync( new RemoveItem(new BasketId(basketId), request.ProductName), CancellationToken.None); if (task.IsSuccess) { return(NoContent()); } } catch (BasketException ex) { return(new JsonResult(ex.Message) { StatusCode = (int)HttpStatusCode.NotFound }); } return(BadRequest()); }