DeliveryItemDetailModel.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using Comal.Classes;
  6. using InABox.Core;
  7. using System.Diagnostics.CodeAnalysis;
  8. using InABox.Mobile;
  9. namespace comal.timesheets
  10. {
  11. public class DeliveryItemDetailModel : DetailModel<DeliveryItemDetailModel, DeliveryItemDetailShell, DeliveryItem>
  12. {
  13. public DeliveryItemDetailModel(IModelHost host, Func<Filter<DeliveryItem>> filter, bool transient = false) : base(host, filter, transient)
  14. {
  15. new DeliveryItemDetailDeliveryDocumentShell();
  16. new DeliveryItemDetailSetoutDocumentShell();
  17. }
  18. public DeliveryItemDetailModel(IModelHost host, Func<Filter<DeliveryItem>> filter, [NotNull] string filename) : base(host, filter, filename)
  19. {
  20. new DeliveryItemDetailDeliveryDocumentShell();
  21. new DeliveryItemDetailSetoutDocumentShell();
  22. }
  23. protected override void Initialize()
  24. {
  25. base.Initialize();
  26. DeliveryDocuments = new CoreObservableCollection<DeliveryItemDetailDeliveryDocumentShell>();
  27. SetoutDocuments = new CoreObservableCollection<DeliveryItemDetailSetoutDocumentShell>();
  28. }
  29. public CoreObservableCollection<DeliveryItemDetailDeliveryDocumentShell> DeliveryDocuments { get; private set; }
  30. public CoreObservableCollection<DeliveryItemDetailSetoutDocumentShell> SetoutDocuments { get; private set; }
  31. public override void BeforeLoad(MultiQuery query)
  32. {
  33. base.BeforeLoad(query);
  34. query.Add<DeliveryDocument>(
  35. new Filter<DeliveryDocument>(x => x.EntityLink.ID).InQuery<DeliveryItem>(Filter(), x => x.Delivery.ID),
  36. DeliveryItemDetailDeliveryDocumentShell.Columns.Columns);
  37. query.Add<SetoutDocument>(
  38. new Filter<SetoutDocument>(x => x.EntityLink.ID).InQuery<DeliveryItem>(Filter(), x => x.SetoutLink.ID),
  39. DeliveryItemDetailSetoutDocumentShell.Columns.Columns);
  40. }
  41. public override void AfterLoad(MultiQuery query)
  42. {
  43. base.AfterLoad(query);
  44. var deldocs = query.Get<DeliveryDocument>()
  45. .Rows
  46. .Select(x => new DeliveryItemDetailDeliveryDocumentShell() { Row = x, Parent = this });
  47. DeliveryDocuments.ReplaceRange(deldocs);
  48. var mfgdocs = query.Get<SetoutDocument>()
  49. .Rows
  50. .Select(x=> new DeliveryItemDetailSetoutDocumentShell() { Row = x, Parent = this})
  51. .ToArray();
  52. SetoutDocuments.ReplaceRange(mfgdocs);
  53. }
  54. }
  55. }