ShipmentStore.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. namespace Comal.Stores
  6. {
  7. internal class ShipmentStore : BaseStore<Shipment>
  8. {
  9. public override void BulkUpdate(IEnumerable<Shipment> entities)
  10. {
  11. base.BulkUpdate(entities);
  12. var updates = new List<DeliveryItem>();
  13. foreach (var shipment in entities)
  14. {
  15. var items = Provider.Load(new Filter<DeliveryItem>(d => d.ShipmentLink.ID).IsEqualTo(shipment.ID));
  16. foreach (var item in items)
  17. {
  18. item.Location.Latitude = shipment.TrackerLink.Location.Latitude;
  19. item.Location.Longitude = shipment.TrackerLink.Location.Longitude;
  20. item.Location.Timestamp = shipment.TrackerLink.Location.Timestamp;
  21. }
  22. updates.AddRange(items);
  23. }
  24. if (updates.Any())
  25. Provider.Save(updates);
  26. }
  27. protected override void AfterSave(Shipment entity)
  28. {
  29. base.AfterSave(entity);
  30. //Deprecated - now handled automagically by ShipmentLink.Location :-)
  31. //IStore<DeliveryItem> iStore = FindSubStore<DeliveryItem>();
  32. //var items = iStore.Load(new Filter<DeliveryItem>(x => x.ShipmentLink.ID).IsEqualTo(entity.ID));
  33. //for (int i=0; i< items.Count(); i++)
  34. //{
  35. // DeliveryItem item = items[i];
  36. // bool bChanged = false;
  37. // if (item.Location.Longitude != entity.Location.Longitude)
  38. // {
  39. // item.Location.Longitude = entity.Location.Longitude;
  40. // bChanged = true;
  41. // }
  42. // if (item.Location.Latitude != entity.Location.Latitude)
  43. // {
  44. // item.Location.Latitude = entity.Location.Latitude;
  45. // bChanged = true;
  46. // }
  47. // if (item.Location.Timestamp != entity.Location.Timestamp)
  48. // {
  49. // item.Location.Timestamp = entity.Location.Timestamp;
  50. // bChanged = true;
  51. // }
  52. // if (bChanged)
  53. // iStore.Save(ref item, "Item Updated from by change in Shipment details");
  54. //}
  55. }
  56. }
  57. }