/Source/Samples/Shop/Bifrost.Samples.Shop.Domain/Shopping/CartHandlers.cs
C# | 32 lines | 28 code | 4 blank | 0 comment | 2 complexity | 6a110c1fe923ea5dd9025c6bb74b5098 MD5 | raw file
Possible License(s): CC-BY-SA-3.0
- using Bifrost.Commands;
- using Bifrost.Domain;
- using Bifrost.Samples.Shop.Domain.Products;
-
- namespace Bifrost.Samples.Shop.Domain.Shopping
- {
- public class CartHandlers : ICommandHandler
- {
- private readonly IAggregatedRootRepository<Cart> _cartRootRepository;
- private readonly IAggregatedRootRepository<Product> _productRootRepository;
-
- public CartHandlers(
- IAggregatedRootRepository<Cart> cartRootRepository,
- IAggregatedRootRepository<Product> productRootRepository)
- {
- _cartRootRepository = cartRootRepository;
- _productRootRepository = productRootRepository;
- }
-
-
- public void Handle(AddProductToCart productToCart)
- {
- var cart = _cartRootRepository.Find(productToCart.Id);
- if( null == cart )
- {
- cart = Cart.Create(productToCart.Id);
- }
- var product = _productRootRepository.Get(productToCart.ProductId);
- cart.AddProduct(product);
- }
- }
- }