public async Task HandleAsync(ProductQuantityChangedEvent @event) { var cartItemId = CartItemReadModel.IdFor(@event.AggregateId.IdAsString(), @event.ProductId.IdAsString()); var cartItem = (await cartItemRepository .FindAllAsync(x => x.Id == cartItemId)) .Single(); var cart = await cartRepository.GetByIdAsync(@event.AggregateId.IdAsString()); cart.TotalItems += @event.NewQuantity - @event.OldQuantity; cartItem.Quantity = @event.NewQuantity; await cartRepository.UpdateAsync(cart); await cartItemRepository.UpdateAsync(cartItem); }
public async Task HandleAsync(ProductAddedEvent @event) { var product = await productRepository.GetByIdAsync(@event.ProductId.IdAsString()); var cart = await cartRepository.GetByIdAsync(@event.AggregateId.IdAsString()); var cartItem = CartItemReadModel.CreateFor(@event.AggregateId.IdAsString(), @event.ProductId.IdAsString()); cartItem.ProductName = product.Name; cartItem.Quantity = @event.Quantity; cart.TotalItems += @event.Quantity; await cartRepository.UpdateAsync(cart); await cartItemRepository.InsertAsync(cartItem); }