DeliveryItemStore.cs 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. namespace Comal.Stores
  6. {
  7. internal class DeliveryItemStore : BaseStore<DeliveryItem>
  8. {
  9. protected override void BeforeSave(DeliveryItem entity)
  10. {
  11. base.BeforeSave(entity);
  12. if (!string.IsNullOrWhiteSpace(entity.SetoutLink.Number) & (entity.Sequence > 0))
  13. entity.Barcode = string.Format("{0}-{1:D3}", entity.SetoutLink.Number, entity.Sequence);
  14. }
  15. protected override void AfterSave(DeliveryItem entity)
  16. {
  17. base.AfterSave(entity);
  18. if (
  19. entity.ManufacturingPacketLink.IsValid()
  20. && entity.ShipmentLink.IsValid()
  21. && entity.ShipmentLink.HasOriginalValue(x => x.ID)
  22. )
  23. {
  24. var filter = new Filter<ManufacturingPacket>(x => x.ID).IsEqualTo(entity.ManufacturingPacketLink.ID);
  25. filter.Ands.Add(new Filter<ManufacturingPacket>(x => x.Completed).IsEqualTo(DateTime.MinValue).Or(x => x.Archived)
  26. .IsEqualTo(DateTime.MinValue));
  27. var row = Provider.Query(
  28. filter,
  29. new Columns<ManufacturingPacket>(x => x.ID, x => x.Completed, x => x.Archived)
  30. ).Rows.FirstOrDefault();
  31. if (row != null)
  32. {
  33. var packet = row.ToObject<ManufacturingPacket>();
  34. if (packet.Completed.IsEmpty())
  35. packet.Completed = DateTime.Now;
  36. if (packet.Archived.IsEmpty())
  37. packet.Archived = DateTime.Now;
  38. Provider.Save(packet);
  39. AuditTrail(packet, new[] { "Closing/Archiving Packet due to Shipment Allocation" });
  40. }
  41. }
  42. }
  43. }
  44. }