void MergeCommonBatches(ITransaction finder) { List <InventoryBatch> merged = new List <InventoryBatch>(); foreach (IEntity result in finder.Results) { Entity <InventoryBatch> currentEntity = result as Entity <InventoryBatch>; InventoryBatch currentBatch = currentEntity.NativeModel; bool batchNotFound = true; for (int i = 0; i < merged.Count; i++) { if (merged[i].BatchNumber == currentBatch.BatchNumber) { merged[i].AddQuantity(currentBatch.Quantity); batchNotFound = false; continue; } } if (batchNotFound) { merged.Add(currentBatch); } } foreach (InventoryBatch batch in merged) { ITransaction deleter = new DeleteFromActiveInventoryAtBatchNumberTransaction(batch.BatchNumber, sqliteStore); deleter.Execute(); ITransaction adder = new AddReceivedBatchToInventoryTransaction(new Entity <InventoryBatch>(batch), sqliteStore); adder.Execute(); } }
void UpdateInventoryBatches(Entity <ReceivedBatch> original, Entity <ReceivedBatch> updated) { ITransaction deleter = null; ProcessColorAndBatchNumberUpdates(original, updated); if (BatchDoesNotExistInInventory(updated.NativeModel.BatchNumber)) { InventoryBatch inventoryBatch = new InventoryBatch( updated.NativeModel.ColorName, updated.NativeModel.BatchNumber, updated.NativeModel.ActivityDate, updated.NativeModel.Quantity ); ITransaction adder = new AddReceivedBatchToInventoryTransaction(new Entity <InventoryBatch>(inventoryBatch), sqliteStore); adder.Execute(); } ITransaction finder = new ListCurrentInventoryTransaction(sqliteStore); finder.Execute(); foreach (IEntity entity in finder.Results) { Entity <InventoryBatch> inventoryEntity = entity as Entity <InventoryBatch>; if (inventoryEntity.NativeModel.BatchNumber == original.NativeModel.BatchNumber) { inventoryEntity.NativeModel.Quantity = GetAdjustedInventoryQuantity( inventoryEntity.NativeModel.BatchNumber, original.NativeModel.Quantity, updated.NativeModel.Quantity ); ITransaction updater = new EditBatchInCurrentInventoryTransaction(inventoryEntity, sqliteStore); updater.Execute(); if (inventoryEntity.NativeModel.Quantity == 0) { deleter = new DeleteDepletedInventoryBatchAtId(inventoryEntity, sqliteStore); } } } if (deleter != null) { deleter.Execute(); } finder.Execute(); MergeCommonBatches(finder); }
public void AddReceivedBatchToInventory(ReceivedBatch batch) { InventoryBatch inventoryBatch = new InventoryBatch( batch.ColorName, batch.BatchNumber, batch.ActivityDate, batch.Quantity ); ITransaction adder = new AddReceivedBatchToInventoryTransaction(new Entity <InventoryBatch>(inventoryBatch), sqliteStore); adder.Execute(); UpdateActiveInventory(); }