using System.Collections.Generic; using System.Linq; using Comal.Classes; using InABox.Core; namespace Comal.Stores { internal class ShipmentStore : BaseStore { public override void BulkUpdate(IEnumerable entities) { base.BulkUpdate(entities); var updates = new List(); foreach (var shipment in entities) { var items = Provider.Load(new Filter(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 iStore = FindSubStore(); //var items = iStore.Load(new Filter(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"); //} } } }