public void RemoveProduct( PricedProductItem productItemToBeRemoved) { Guard.Against.Null(productItemToBeRemoved, nameof(productItemToBeRemoved)); if (Status != CartStatus.Pending) { throw new InvalidOperationException($"Removing product from the cart in '{Status}' status is not allowed."); } var existingProductItem = FindProductItemMatchingWith(productItemToBeRemoved); if (existingProductItem is null) { throw new InvalidOperationException($"Product with id `{productItemToBeRemoved.ProductId}` and price '{productItemToBeRemoved.UnitPrice}' was not found in cart."); } if (existingProductItem.HasEnough(productItemToBeRemoved.Quantity)) { throw new InvalidOperationException($"Cannot remove {productItemToBeRemoved.Quantity} items of Product with id `{productItemToBeRemoved.ProductId}` as there are only ${existingProductItem.Quantity} items in card"); } var @event = ProductRemoved.Create(Id, productItemToBeRemoved); Enqueue(@event); Apply(@event); }
public void DecreaseCount() { if (ProductCount >= 1) { ProductCount--; } ProductRemoved?.Invoke(this); }
public async Task Handle(ProductRemoved notification) { if (notification == null) { throw new ArgumentNullException(nameof(notification)); } var collection = _mongoClient.GetDatabase(_settings.Database).GetCollection <CategoryAggregate>(nameof(CategoryAggregate)); await collection.UpdateOneAsync(Builders <CategoryAggregate> .Filter.Eq(p => p.OriginalId, notification.SourceId), Builders <CategoryAggregate> .Update.Inc(p => p.ProductCount, -1)); }
/// <summary> /// Removes a product from the list /// </summary> /// <param name="productId"></param> void IProductStore.RemoveProduct(Guid productId) { Thread.Sleep(5000);//DO NOT REMOVE; TO SIMULATE A BUGGY/SLOW SERVICE IProduct product = _products.FirstOrDefault(p => p.Id.Equals(productId)); if (product != null) { // Use the lock object to avoid concurrency issues lock (_productsLock) { _products.Remove(product); } ProductRemoved?.Invoke(productId); } }
private void Apply(ProductRemoved domainEvent) { var cartLine = cartState.Lines.Single(line => line.ProductName == domainEvent.ProductName); if (cartLine.Quantity == 1) { cartState.Lines.Remove(cartLine); } else { cartLine.Quantity--; } if (!cartState.Lines.Any()) { Become(Empty); } }
public CommandHandlingResult RemoveProduct(string productNumber) { if (!Products.Any(p => p.ProductNumber == productNumber)) { return(CommandHandlingResult.Fail("Error: the order does not contain the specified product.")); } if (this.Status != OrderStatus.InProgress) { return(CommandHandlingResult.Fail("Error: products can only be removed from in progress orders.")); } var e = new ProductRemoved(this.OrderNumber, productNumber); Handle(e); return(CommandHandlingResult.Success(e)); }
private void Apply(ProductRemoved @event) { Version++; var productItemToBeRemoved = @event.ProductItem; var existingProductItem = FindProductItemMatchingWith(@event.ProductItem); if (existingProductItem.HasTheSameQuantity(productItemToBeRemoved)) { ProductItems.Remove(existingProductItem); return; } ProductItems.Replace( existingProductItem, existingProductItem.Substract(productItemToBeRemoved) ); }
private async void Handle(ProductRemoved e) { Console.WriteLine($"Product #{e.ProductNumber} removed from order #{e.OrderNumber}."); using (var dbContext = new StoreDBContext()) { var order = dbContext.Orders.FirstOrDefault(o => o.OrderNumber == e.OrderNumber); if (order != null) { dbContext.Entry(order).Collection(o => o.Products).Load(); var product = order.Products.FirstOrDefault(p => p.ProductNumber == e.ProductNumber); if (product != null) { order.Products.Remove(product); await dbContext.SaveChangesAsync(); } } } }
private void OnProductRemoved(ProductRemoved e) { _productIds.Remove(e.ProductId); }
private void Handle(ProductRemoved e) { Products.Remove(Products.Find(p => p.ProductNumber == e.ProductNumber)); }
public void Apply(ProductRemoved @event) { TotalItemsCount -= @event.ProductItem.Quantity; }
public void Apply(ProductRemoved @event) { Id = Guid.NewGuid(); CartId = @event.CartId; Description = $"Created tentative Cart with id {@event.CartId}"; }
private void Handle(RemoveProduct command) { var domainEvent = new ProductRemoved(command.ProductName); Persist(domainEvent, Apply); }
private void ApplyProductRemoved(ProductRemoved @event) { var line = _lines.FirstOrDefault(x => x.Product == @event.Product); if (line != null) { _lines.Remove(line); ReCalculateTotalPrice(); } }
private void Handle(ProductRemoved @event) { EnsureModify(); Items.RemoveWhere(i => i.Identity == @event.Sku); }