public async Task HandleUpdatedProductAsync(Guid productId)
        {
            var product = await _productsRepository.GetAsync(productId);

            var carts = await _cartsRepository.GetAllWithProduct(productId);

            foreach (var cart in carts)
            {
                cart.UpdateProduct(Product.Create(product.Id, product.Name, product.Price));
            }
            await _cartsRepository.UpdateManyAsync(carts);
        }
예제 #2
0
        public async Task HandleAsync(ProductDeletedEvent @event, ICorrelationContext context)
        {
            await _productsRepository.DeleteAsync(@event.Id);

            var carts = await _cartsRepository.GetAllWithProduct(@event.Id)
                        .ContinueWith(t => t.Result.ToList());

            foreach (var cart in carts)
            {
                cart.DeleteProduct(@event.Id);
            }

            await _cartsRepository.UpdateManyAsync(carts);
        }
        public async Task HandleAsync(ProductUpdated @event, ICorrelationContext context)
        {
            var product = new Product(@event.Id, @event.Name, @event.Price,
                                      @event.Quantity);
            await _productsRepository.UpdateAsync(product);

            var carts = await _cartsRepository.GetAllWithProduct(product.Id)
                        .ContinueWith(t => t.Result.ToList());

            foreach (var cart in carts)
            {
                cart.UpdateProduct(product);
            }
            await _cartsRepository.UpdateManyAsync(carts);
        }