123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using System.Collections.Generic;
- using System.Linq;
- using Comal.Classes;
- using InABox.Core;
- namespace Comal.Stores
- {
- internal class ShipmentStore : BaseStore<Shipment>
- {
- public override void BulkUpdate(IEnumerable<Shipment> entities)
- {
- base.BulkUpdate(entities);
- var updates = new List<DeliveryItem>();
- foreach (var shipment in entities)
- {
- var items = Provider.Load(new Filter<DeliveryItem>(d => d.ShipmentLink.ID).IsEqualTo(shipment.ID));
- foreach (var item in items)
- {
- item.Location.Latitude = shipment.TrackerLink.Location.Latitude;
- item.Location.Longitude = shipment.TrackerLink.Location.Longitude;
- item.Location.Timestamp = shipment.TrackerLink.Location.Timestamp;
- }
- updates.AddRange(items);
- }
- if (updates.Any())
- Provider.Save(updates);
- }
- protected override void AfterSave(Shipment entity)
- {
- base.AfterSave(entity);
- //Deprecated - now handled automagically by ShipmentLink.Location :-)
- //IStore<DeliveryItem> iStore = FindSubStore<DeliveryItem>();
- //var items = iStore.Load(new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(entity.ID));
- //for (int i=0; i< items.Count(); i++)
- //{
- // DeliveryItem item = items[i];
- // bool bChanged = false;
- // if (item.Location.Longitude != entity.Location.Longitude)
- // {
- // item.Location.Longitude = entity.Location.Longitude;
- // bChanged = true;
- // }
- // if (item.Location.Latitude != entity.Location.Latitude)
- // {
- // item.Location.Latitude = entity.Location.Latitude;
- // bChanged = true;
- // }
- // if (item.Location.Timestamp != entity.Location.Timestamp)
- // {
- // item.Location.Timestamp = entity.Location.Timestamp;
- // bChanged = true;
- // }
- // if (bChanged)
- // iStore.Save(ref item, "Item Updated from by change in Shipment details");
- //}
- }
- }
- }
|