using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using Comal.Classes; using InABox.Core; using System.Diagnostics.CodeAnalysis; using InABox.Mobile; namespace comal.timesheets { public class DeliveryItemDetailModel : DetailModel { public DeliveryItemDetailModel(IModelHost host, Func> filter, bool transient = false) : base(host, filter, transient) { new DeliveryItemDetailDeliveryDocumentShell(); new DeliveryItemDetailSetoutDocumentShell(); } public DeliveryItemDetailModel(IModelHost host, Func> filter, [NotNull] string filename) : base(host, filter, filename) { new DeliveryItemDetailDeliveryDocumentShell(); new DeliveryItemDetailSetoutDocumentShell(); } protected override void Initialize() { base.Initialize(); DeliveryDocuments = new CoreObservableCollection(); SetoutDocuments = new CoreObservableCollection(); } public CoreObservableCollection DeliveryDocuments { get; private set; } public CoreObservableCollection SetoutDocuments { get; private set; } public override void BeforeLoad(MultiQuery query) { base.BeforeLoad(query); query.Add( new Filter(x => x.EntityLink.ID).InQuery(Filter(), x => x.Delivery.ID), DeliveryItemDetailDeliveryDocumentShell.Columns.Columns); query.Add( new Filter(x => x.EntityLink.ID).InQuery(Filter(), x => x.SetoutLink.ID), DeliveryItemDetailSetoutDocumentShell.Columns.Columns); } public override void AfterLoad(MultiQuery query) { base.AfterLoad(query); var deldocs = query.Get() .Rows .Select(x => new DeliveryItemDetailDeliveryDocumentShell() { Row = x, Parent = this }); DeliveryDocuments.ReplaceRange(deldocs); var mfgdocs = query.Get() .Rows .Select(x=> new DeliveryItemDetailSetoutDocumentShell() { Row = x, Parent = this}) .ToArray(); SetoutDocuments.ReplaceRange(mfgdocs); } } }