Exemple #1
0
        private AddProductResult TryUpdate(Variant item, int quantity, ProductBasketItem matchingItem)
        {
            var newQuantity = matchingItem.Quantity + quantity;

            if (newQuantity > MaximumQuantityForItem)
            {
                return(new AddProductResult.QuantityExceeded(newQuantity - MaximumQuantityForItem));
            }

            ApplyChange(new ExistingProductUpdatedEvent(Id, matchingItem.ItemId, item, quantity));
            return(new AddProductResult.ProductUpdated());
        }
Exemple #2
0
        public AddProductResult AddVariant(Variant item, int quantity)
        {
            if (quantity > MaximumQuantityForItem)
            {
                return(new AddProductResult.QuantityExceeded(quantity - MaximumQuantityForItem));
            }

            var matchingItem = Items.Cast <ProductBasketItem>()
                               .FirstOrDefault(x => x.VariantId == item.VariantId);

            if (matchingItem != null)
            {
                return(TryUpdate(item, quantity, matchingItem));
            }

            RemoveMatchingExpiredItems(item);

            ApplyChange(new NewProductAddedEvent(Id, ProductBasketItem.Create(item, quantity)));
            return(new AddProductResult.NewProductAdded());
        }