DigitalFormModel.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.Mobile;
  7. using System.Diagnostics.CodeAnalysis;
  8. namespace comal.timesheets
  9. {
  10. public class DigitalFormModel : ListModel<DigitalFormModel,DigitalFormShell,EmployeeDigitalForm>
  11. {
  12. public DigitalFormModel(IModelHost host, Func<Filter<EmployeeDigitalForm>> filter, bool transient = false) : base(host, filter, transient)
  13. {
  14. }
  15. public DigitalFormModel(IModelHost host, Func<Filter<EmployeeDigitalForm>> filter, [NotNull] string filename) : base(host, filter, filename)
  16. {
  17. }
  18. protected override void Initialize()
  19. {
  20. new DigitalFormLayoutShell();
  21. new DigitalFormDocumentShell();
  22. base.Initialize();
  23. Layouts = new CoreObservableCollection<DigitalFormLayoutShell>();
  24. _documents = new CoreObservableCollection<IDocumentShell>();
  25. }
  26. public CoreObservableCollection<DigitalFormLayoutShell> Layouts { get; private set; }
  27. private CoreObservableCollection<IDocumentShell> _documents;
  28. public IEnumerable<IDocumentShell> Documents => _documents;
  29. // public override Columns<(.+)> Columns => DigitalFormShell.Columns.Columns;
  30. public override void BeforeLoad(MultiQuery query)
  31. {
  32. base.BeforeLoad(query);
  33. query.Add(
  34. new Filter<DigitalFormLayout>(x => x.Form.ID).InQuery(Filter(), x => x.Form.ID)
  35. .And(x => x.Type).IsEqualTo(DFLayoutType.Mobile)
  36. .And(x => x.Active).IsEqualTo(true),
  37. DigitalFormLayoutShell.Columns.Columns
  38. );
  39. query.Add(
  40. new Filter<DigitalFormDocument>(x => x.EntityLink.ID).InQuery(Filter(), x => x.Form.ID),
  41. DigitalFormDocumentShell.Columns.Columns
  42. );
  43. }
  44. public override void AfterLoad(MultiQuery query)
  45. {
  46. base.AfterLoad(query);
  47. Layouts.ReplaceRange(
  48. query.Get<DigitalFormLayout>()
  49. .Rows
  50. .Select(x => new DigitalFormLayoutShell() { Row = x, Parent = this })
  51. .ToArray()
  52. );
  53. _documents.ReplaceRange(
  54. query.Get<DigitalFormDocument>()
  55. .Rows
  56. .Select(x => new DigitalFormDocumentShell() { Row = x, Parent = this })
  57. .ToArray()
  58. );
  59. }
  60. }
  61. }