|
@@ -16,6 +16,7 @@ public class StockMovementStore : BaseStore<StockMovement>
|
|
|
// These will be initialised in BeforeSave
|
|
|
HoldingDictionary holdingData = null!;
|
|
|
StockMovement[] mvtData = null!;
|
|
|
+ HashSet<Guid> currentIDs = new();
|
|
|
|
|
|
protected override void BeforeSave(IEnumerable<StockMovement> entities)
|
|
|
{
|
|
@@ -25,7 +26,9 @@ public class StockMovementStore : BaseStore<StockMovement>
|
|
|
base.BeforeSave(entity);
|
|
|
}
|
|
|
|
|
|
- mvtData = StockHoldingStore.LoadMovementData(this, entities.Select(x => x.ID).ToArray());
|
|
|
+ currentIDs = entities.Select(x => x.ID).Where(x => x != Guid.Empty).ToHashSet();
|
|
|
+
|
|
|
+ mvtData = StockHoldingStore.LoadMovementData(this, currentIDs.ToArray());
|
|
|
holdingData = StockHoldingStore.LoadStockHoldings(this, mvtData);
|
|
|
|
|
|
StockHoldingStore.ModifyHoldings(mvtData, holdingData, StockHoldingStore.Action.Decrease);
|
|
@@ -68,8 +71,11 @@ public class StockMovementStore : BaseStore<StockMovement>
|
|
|
|
|
|
protected override void AfterSave(IEnumerable<StockMovement> entities)
|
|
|
{
|
|
|
- mvtData = StockHoldingStore.LoadMovementData(this, entities.Select(x => x.ID).ToArray());
|
|
|
- holdingData = StockHoldingStore.LoadStockHoldings(this, mvtData);
|
|
|
+ var newIDs = entities.Select(x => x.ID).Where(x => !currentIDs.Contains(x)).ToArray();
|
|
|
+ var newMvts = StockHoldingStore.LoadMovementData(this, newIDs);
|
|
|
+ StockHoldingStore.LoadStockHoldings(this, newMvts, holdingData);
|
|
|
+
|
|
|
+ mvtData = mvtData.Concatenate(newMvts);
|
|
|
|
|
|
// Update the Relevant StockHolding with the details of this movement
|
|
|
StockHoldingStore.ModifyHoldings(mvtData, holdingData, StockHoldingStore.Action.Increase);
|