Exemplo n.º 1
0
        public async Task HandleAsync(ProductQuantityChanged @event)
        {
            var cartItemId = OrderItemReadModel.IdFor(@event.AggregateId.IdAsString(), @event.ProductId.IdAsString());
            var cartItem   = (await orderItemRepository
                              .FindAllAsync(x => x.Id == cartItemId))
                             .Single();
            var cart = await orderRepository.GetByIdAsync(@event.AggregateId.IdAsString());

            cart.TotalItems  += @event.NewQuantity - @event.OldQuantity;
            cartItem.Quantity = @event.NewQuantity;

            await orderRepository.UpdateAsync(cart);

            await orderItemRepository.UpdateAsync(cartItem);
        }
Exemplo n.º 2
0
        public async Task HandleAsync(ProductAdded @event)
        {
            var product = await productRepository.GetByIdAsync(@event.ProductId.IdAsString());

            var cart = await orderRepository.GetByIdAsync(@event.AggregateId.IdAsString());

            var cartItem = OrderItemReadModel.CreateFor(@event.AggregateId.IdAsString(), @event.ProductId.IdAsString());

            cartItem.ProductName = product.Name;
            cartItem.Quantity    = @event.Quantity;
            cart.TotalItems     += @event.Quantity;
            await orderRepository.UpdateAsync(cart);

            await orderItemRepository.InsertAsync(cartItem);
        }