public void ChangeProductQuantity(ProductId productId, int quantity) { var validator = new ProductInInventoryValidator().And(new CartItemInCartValidator(Items)); var result = validator.Validate(new CartItem(productId, quantity)); if (!result.IsValid) { throw new CartException(result.Errors.First().ErrorMessage); } RaiseEvent(new ProductQuantityChangedEvent(productId, GetCartItemByProduct(productId).Quantity, quantity)); }
public void AddProduct(CartItem cartItem) { var validator = new ProductInInventoryValidator().And(new CartItemNotInCartValidator(Items)); var result = validator.Validate(cartItem); if (!result.IsValid) { throw new CartException(result.Errors.First().ErrorMessage); } RaiseEvent(new ProductAddedEvent(cartItem.ProductId, cartItem.Quantity)); }