using System; using System.Collections.Generic; using System.Linq; using Comal.Classes; using InABox.Core; using InABox.Mobile; using System.Diagnostics.CodeAnalysis; namespace comal.timesheets { public class DigitalFormModel : ListModel { public DigitalFormModel(IModelHost host, Func> filter, bool transient = false) : base(host, filter, transient) { } public DigitalFormModel(IModelHost host, Func> filter, [NotNull] string filename) : base(host, filter, filename) { } protected override void Initialize() { new DigitalFormLayoutShell(); new DigitalFormDocumentShell(); base.Initialize(); Layouts = new CoreObservableCollection(); _documents = new CoreObservableCollection(); } public CoreObservableCollection Layouts { get; private set; } private CoreObservableCollection _documents; public IEnumerable Documents => _documents; // public override Columns<(.+)> Columns => DigitalFormShell.Columns.Columns; public override void BeforeLoad(MultiQuery query) { base.BeforeLoad(query); query.Add( new Filter(x => x.Form.ID).InQuery(Filter(), x => x.Form.ID) .And(x => x.Type).IsEqualTo(DFLayoutType.Mobile) .And(x => x.Active).IsEqualTo(true), DigitalFormLayoutShell.Columns.Columns ); query.Add( new Filter(x => x.EntityLink.ID).InQuery(Filter(), x => x.Form.ID), DigitalFormDocumentShell.Columns.Columns ); } public override void AfterLoad(MultiQuery query) { base.AfterLoad(query); Layouts.ReplaceRange( query.Get() .Rows .Select(x => new DigitalFormLayoutShell() { Row = x, Parent = this }) .ToArray() ); _documents.ReplaceRange( query.Get() .Rows .Select(x => new DigitalFormDocumentShell() { Row = x, Parent = this }) .ToArray() ); } } }