コード例 #1
0
        private async Task CreatePurchaseOrder(int buyerId, int[] catalogItemIds)
        {
            var basketModel = new CreateBasketModel {
                BuyerId = buyerId
            };
            var createNewBasketCommand = _autoMapper.Map <CreateBasketModel, CreateBasketForUserCommand>(basketModel);

            await _commandBus.SendAsync(createNewBasketCommand);

            var basket = await _queryBus.SendAsync <GetBasketByBuyerId, Basket>(new GetBasketByBuyerId { BuyerId = buyerId });

            foreach (var catalogItemId in catalogItemIds)
            {
                var basketItemModel = new BasketItemModel
                {
                    BasketId = basket.BasketId, Price = 10M, Quantity = 1, CatalogItemId = catalogItemId
                };
                var addItemToBasketCommand = _autoMapper.Map <BasketItemModel, AddItemToBasketCommand>(basketItemModel);
                await _commandBus.SendAsync(addItemToBasketCommand);
            }

            basket = await _queryBus.SendAsync <GetBasketByBuyerId, Basket>(new GetBasketByBuyerId { BuyerId = buyerId });

            var createPurchaseOrderModel = new CreatePurchaseOrderModel();

            createPurchaseOrderModel.BasketId = basket.BasketId.ToString();
            var shippingAddress = new Address("126 BowhillWay", "Harlow",
                                              "Essex", "United Kingdom", "CM20 2FH");
            var crateOrderCommand = new CreatePurchaseOrderCommand(Guid.Parse(createPurchaseOrderModel.BasketId), shippingAddress);
            await _commandBus.SendAsync(crateOrderCommand);
        }
コード例 #2
0
        public async Task <IActionResult> Create(
            [FromServices] ICommandHandlerAsync <CreatePurchaseOrderCommand> createCommandHandler,
            CreatePurchaseOrderCommand createCommand)
        {
            var result = await createCommandHandler.HandleAsync(createCommand);

            return(RedirectToAction("Index"));
        }
コード例 #3
0
        public async Task <PurchaseOrder> CreatePurchaseOrderAsync(
            [GraphQLType(typeof(CreatePurchaseOrderInputType))][GraphQLName("input")]
            CreatePurchaseOrderCommand input, [Service] ISheaftMediatr mediatr,
            PurchaseOrdersByIdBatchDataLoader purchaseOrdersDataLoader, CancellationToken token)
        {
            var result = await ExecuteAsync <CreatePurchaseOrderCommand, Guid>(mediatr, input, token);

            return(await purchaseOrdersDataLoader.LoadAsync(result, token));
        }
コード例 #4
0
        public async Task Post([FromBody] CreatePurchaseOrderModel createPurchaseOrderModel)
        {
            _logger.LogInformation($"Create purchase order requested for basket {createPurchaseOrderModel.BasketId}");

            //Assumption: We call an API Or we get Address From User
            var shippingAddress = new Address("126 BowhillWay", "Harlow",
                                              "Essex", "United Kingdom", "CM20 2FH");
            var crateOrderCommand = new CreatePurchaseOrderCommand(Guid.Parse(createPurchaseOrderModel.BasketId), shippingAddress);
            await _commandBus.SendAsync(crateOrderCommand);
        }
        public async Task <ActionResult <PurchaseOrderDetailView> > CreateNewPurchaseOrder([FromBody] CreatePurchaseOrderCommand newPurchaseOrder)
        {
            var purchaseOrderId = await _Mediator.Send(newPurchaseOrder);

            var purchaseOrderDetail = await _Mediator.Send(new GetPurchaseOrderByIdQuery()
            {
                Id = purchaseOrderId
            });

            return(StatusCode(201, purchaseOrderDetail));
        }