RequisitionItemStore.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. namespace Comal.Stores
  6. {
  7. internal class RequisitionItemStore : BaseStore<RequisitionItem>
  8. {
  9. private void UpdateTrackingKanban(RequisitionItem entity)
  10. {
  11. var requi = new Requisition
  12. { ID = entity.RequisitionLink.ID, Filled = entity.RequisitionLink.Filled, Archived = entity.RequisitionLink.Archived };
  13. UpdateTrackingKanban<RequisitionKanban, Requisition, RequisitionLink>(requi, r =>
  14. {
  15. if (!r.Archived.Equals(DateTime.MinValue))
  16. return KanbanCategory.Complete;
  17. if (!r.Filled.Equals(DateTime.MinValue))
  18. return KanbanCategory.Waiting;
  19. if (Provider.Query(
  20. new Filter<RequisitionItem>(x => x.RequisitionLink.ID).IsEqualTo(r.ID)
  21. .And(x=>x.Picked).IsNotEqualTo(DateTime.MinValue),
  22. new Columns<RequisitionItem>(x => x.ID)
  23. ).Rows.Any()
  24. )
  25. return KanbanCategory.InProgress;
  26. return KanbanCategory.Open;
  27. });
  28. }
  29. protected override void AfterSave(RequisitionItem entity)
  30. {
  31. base.AfterSave(entity);
  32. UpdateTrackingKanban(entity);
  33. }
  34. protected override void AfterDelete(RequisitionItem entity)
  35. {
  36. base.AfterDelete(entity);
  37. UpdateTrackingKanban(entity);
  38. }
  39. }
  40. }