public async Task Handle(ProductAddedDomainEvent @event, CancellationToken cancellationToken) { //Additional logic for product domain event handler e.g. validation, publish restriction. //event for e.g. SignalR var integrationEvent = new ProductAddedIntegrationEvent(@event.ProductId, @event.Name, @event.Price, @event.Manufacturer); await _productIntegrationEventService.AddAndSaveEventAsync(integrationEvent); }
public async Task <bool> Handle(AddNewProductCommand request, CancellationToken cancellationToken) { var product = new Product(request.ProductId, request.StoreId, request.Name, request.Description, request.ProductCategory, request.Units, request.UnitPrice, request.PictureUrl); var productAddedIntegrationEvent = new ProductAddedIntegrationEvent(product.ProductId, request.Units, request.UnitPrice); await _eventService.AddAndSaveEventAsync(productAddedIntegrationEvent); await _productRepository.AddNewProductAsync(product); return(await _productRepository.UnitOfWork .SaveEntitiesAsync(cancellationToken)); }
public async Task <IActionResult> Add([FromBody] Product catalogItem) { // TODO - Extraer el saveContext a un repository para aplicar el repository pattern. var catalogItemAdded = catalogContext.Add(catalogItem); await catalogContext.SaveChangesAsync(); var productAddedEvent = new ProductAddedIntegrationEvent(catalogItem); await catalogIntegrationEventService.AddAndSaveEventAsync(productAddedEvent); await catalogIntegrationEventService.PublishEventsThroughEventBusAsync(productAddedEvent); return(Ok(catalogItemAdded.Entity.Id)); //return CreatedAtAction(nameof(GetCatalogItem), new { id = catalogItemAdded.Entity.Id }); }