public Task HandleAsync(
     OrderStatusChangedToAwaitingStockValidationIntegrationEvent integrationEvent)
 {
     // Save the updated status in the read model and notify the client via SignalR.
     return(UpdateReadModelAndSendNotificationAsync(integrationEvent.OrderId,
                                                    integrationEvent.OrderStatus, integrationEvent.Description, integrationEvent.BuyerId));
 }
        public async Task Handle(OrderStatusChangedToAwaitingStockValidationDomainEvent domainEvent, CancellationToken cancellationToken)
        {
            _logger.CreateLogger <OrderStatusChangedToAwaitingStockValidationDomainEvent>()
            .LogTrace("Order with Id: {OrderId} has been successfully updated to status {Status} ({Id})",
                      domainEvent.OrderId, nameof(OrderStatus.AwaitingStockValidation), OrderStatus.AwaitingStockValidation.Id);

            var order = await _orderRepository.GetAsync(domainEvent.OrderId);

            var buyer = await _buyerRepository.FindByIdAsync(order.GetBuyerId.Value.ToString());

            var orderStockList = domainEvent.OrderItems
                                 .Select(orderItem => new OrderStockItem(orderItem.ProductId, orderItem.GetUnits()));

            var integrationEvent = new OrderStatusChangedToAwaitingStockValidationIntegrationEvent(
                order.Id, order.OrderStatus.Name, buyer.Name, orderStockList);
            await _orderingIntegrationEventService.AddAndSaveEventAsync(integrationEvent);
        }
Example #3
0
        public async Task Handle(OrderStatusChangedToAwaitingStockValidationDomainEvent notification, CancellationToken cancellationToken)
        {
            //Publish integration event here.

            //Prepare orderStockItems,
            //Publish integration event.

            var orderItems = notification.OrderItems;
            List <OrderStockItem> orderStockItems = new List <OrderStockItem>();

            foreach (var item in orderItems)
            {
                orderStockItems.Add(new OrderStockItem(item.ProductId, item.GetUnits()));
            }

            _logger.LogInformation(" [x] OrderStatusChangedToAwaitingStockValidationDomainEventHandler: Handling domain event and creating an OrderStatusChangedToAwaitingStockValidationIntegrationEvent to publish to RabbitMQ...");
            var integrationEvent = new OrderStatusChangedToAwaitingStockValidationIntegrationEvent(orderId: notification.OrderId,
                                                                                                   orderStockItems: orderStockItems);

            await _orderingIntegrationEventService.AddIntegrationEventToLog(@integrationEvent, null);

            await _orderingIntegrationEventService.PublishEvent(integrationEvent);
        }
Example #4
0
 public async Task OrderStarted(OrderStatusChangedToAwaitingStockValidationIntegrationEvent @event)
 {
     var handler = _serviceProvider.GetRequiredService <OrderStatusChangedToAwaitingStockValidationIntegrationEventHandler>();
     await handler.Handle(@event);
 }
 public Task HandleAsync(
     OrderStatusChangedToAwaitingStockValidationIntegrationEvent @event,
     [FromServices] OrderStatusChangedToAwaitingStockValidationIntegrationEventHandler handler) =>
 handler.Handle(@event);