123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- using System;
- using System.Linq;
- using Comal.Classes;
- using InABox.Core;
- namespace Comal.Stores
- {
- internal class DeliveryItemStore : BaseStore<DeliveryItem>
- {
- protected override void BeforeSave(DeliveryItem entity)
- {
- base.BeforeSave(entity);
- if (!string.IsNullOrWhiteSpace(entity.SetoutLink.Number) & (entity.Sequence > 0))
- entity.Barcode = string.Format("{0}-{1:D3}", entity.SetoutLink.Number, entity.Sequence);
- }
- protected override void AfterSave(DeliveryItem entity)
- {
- base.AfterSave(entity);
- if (
- entity.ManufacturingPacketLink.IsValid()
- && entity.ShipmentLink.IsValid()
- && entity.ShipmentLink.HasOriginalValue(x => x.ID)
- )
- {
- var filter = new Filter<ManufacturingPacket>(x => x.ID).IsEqualTo(entity.ManufacturingPacketLink.ID);
- filter.Ands.Add(new Filter<ManufacturingPacket>(x => x.Completed).IsEqualTo(DateTime.MinValue).Or(x => x.Archived)
- .IsEqualTo(DateTime.MinValue));
- var row = Provider.Query(
- filter,
- new Columns<ManufacturingPacket>(x => x.ID, x => x.Completed, x => x.Archived)
- ).Rows.FirstOrDefault();
- if (row != null)
- {
- var packet = row.ToObject<ManufacturingPacket>();
- if (packet.Completed.IsEmpty())
- packet.Completed = DateTime.Now;
- if (packet.Archived.IsEmpty())
- packet.Archived = DateTime.Now;
- Provider.Save(packet);
- AuditTrail(packet, new[] { "Closing/Archiving Packet due to Shipment Allocation" });
- }
- }
- }
- }
- }
|