-
-
Save dcomartin/62cacd3454252edd4805a8a890514764 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ShoppingCartDomain | |
{ | |
private readonly ShoppingCart _shoppingCart; | |
public ShoppingCartDomain(ShoppingCart shoppingCart) | |
{ | |
_shoppingCart = shoppingCart; | |
} | |
public void AddItem(Guid productId, int quantity, decimal price) | |
{ | |
var existingItem = _shoppingCart.Items.SingleOrDefault(x => x.ProductId == productId); | |
if (existingItem != null) | |
{ | |
existingItem.Quantity += quantity; | |
} | |
else | |
{ | |
_shoppingCart.Items.Add(new ShoppingCartItem(_shoppingCart.ShoppingCartId, productId, quantity, price)); | |
} | |
} | |
public void RemoveItem(Guid productId) | |
{ | |
var product = _shoppingCart.Items.SingleOrDefault(x => x.ProductId == productId); | |
if (product != null) | |
{ | |
_shoppingCart.Items.Remove(product); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment