public void Apply(OrderItemQuantitySubtracted @event) { OrderLine line = Lines.FirstOrDefault(x => x.ProductId == @event.ProductNumber); if (line != null && line.Quantity >= @event.Quantity) { line.Quantity -= @event.Quantity; } }
public void Handle(OrderItemQuantitySubtracted message) { WarehouseItemReadView warehouseItem = db.WarehouseItemReadViews.FirstOrDefault(l => l.WarehouseId == message.WarehouseId && l.ProductId == message.ProductNumber); if (warehouseItem != null) { warehouseItem.Quantity += message.Quantity; db.SaveChanges(); } }
public void Handle(OrderItemQuantitySubtracted message) { var orderItemView = db.OrderLineViews.FirstOrDefault(item => item.OrderId == message.OrderId && item.ProductId == message.ProductNumber); if (!IsOrderExist(message.OrderId) || orderItemView == null) { return; } orderItemView.Quantity -= message.Quantity; db.SaveChanges(); }
public void SubtractItemQuantity(int productNumber, int qty) { var line = Lines.FirstOrDefault(l => l.ProductId == productNumber); if (line != null) { int eventQuantity = 0; int difference = line.Quantity - qty; if (difference > 0) { eventQuantity = qty; } else { eventQuantity = line.Quantity; RemoveLine(productNumber); } var @event = new OrderItemQuantitySubtracted(Id, line.WarehouseId, productNumber, eventQuantity); Apply(@event); Append(@event); } }