12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- using Comal.Classes;
- using Comal.Stores;
- using InABox.Core;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace PRSStores;
- public class StockMovementStore : BaseStore<StockMovement>
- {
- protected override void BeforeSave(StockMovement sm)
- {
- base.BeforeSave(sm);
-
- // If this movement is an Update (instead of Insert),
- // we need to reduce the old stock holding before updating the new one
- if (sm.ID != Guid.Empty)
- StockHoldingStore.UpdateStockHolding(sm.ID,StockHoldingStore.Action.Decrease);
- }
- protected override void AfterSave(StockMovement sm)
- {
- // Update the Relevant StockHolding with the details of this movement
- StockHoldingStore.UpdateStockHolding(sm.ID,StockHoldingStore.Action.Increase);
-
- // Update the Job requisition item status (if applicable)
- if (sm.JobRequisitionItem.ID != Guid.Empty)
- JobRequisitionItemStore.UpdateStatus(
- this,
- sm.JobRequisitionItem.ID,
- sm.HasOriginalValue(x=>x.ID)
- ? JobRequisitionItemAction.Created
- : JobRequisitionItemAction.Updated
- );
- base.AfterSave(sm);
- }
- protected override void BeforeDelete(StockMovement entity)
- {
- base.BeforeDelete(entity);
-
- // We need to do this in before delete, because aotherwise we wont have the data
- // that we need to pull to properly update the stockholdings
- StockHoldingStore.UpdateStockHolding(entity.ID,StockHoldingStore.Action.Decrease);
-
- // Now let's pull the requisition ID, so that we can clean this up properly
- // in AfterDelete()
- entity.JobRequisitionItem.ID = Provider.Query(
- new Filter<StockMovement>(x => x.ID).IsEqualTo(entity.ID),
- new Columns<StockMovement>(x => x.JobRequisitionItem.ID)
- ).Rows
- .FirstOrDefault()?
- .Get<StockMovement, Guid>(x => x.JobRequisitionItem.ID) ?? Guid.Empty;
- }
- protected override void AfterDelete(StockMovement sm)
- {
- if (sm.JobRequisitionItem.ID != Guid.Empty)
- JobRequisitionItemStore.UpdateStatus(this, sm.JobRequisitionItem.ID, JobRequisitionItemAction.Deleted);
- base.AfterDelete(sm);
- }
- }
|