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));
        }
Exemple #2
0
        public async Task <bool> Handle(RemoveProductCommand request, CancellationToken cancellationToken)
        {
            var product = await _productRepository.GetProductByIdAsync(request.Id);

            var productRemovedIntegrationEvent = new ProductRemovedIntegrationEvent(product.ProductId);

            await _eventService.AddAndSaveEventAsync(productRemovedIntegrationEvent);

            await _productRepository.RemoveProductAsync(product);

            return(await _productRepository.UnitOfWork
                   .SaveEntitiesAsync(cancellationToken));
        }