LookupModel.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using InABox.Core;
  5. using System.Diagnostics.CodeAnalysis;
  6. using Xamarin.Forms;
  7. namespace comal.timesheets
  8. {
  9. public abstract class LookupModel<TParent, TItem, TEntity> : ListModel<TParent, TItem, TEntity>, ILookupModel
  10. where TParent : LookupModel<TParent, TItem, TEntity>
  11. where TEntity : Entity, IRemotable, IPersistent, new()
  12. where TItem : Shell<TParent, TEntity>, ILookupShell, new()
  13. {
  14. protected LookupModel(IModelHost host, Func<Filter<TEntity>> filter, bool transient = false) : base(
  15. host, filter, transient)
  16. {
  17. }
  18. protected LookupModel(IModelHost host, Func<Filter<TEntity>> filter, [NotNull] string filename) : base(
  19. host, filter, filename)
  20. {
  21. }
  22. protected override void Initialize()
  23. {
  24. base.Initialize();
  25. _selected.Clear();
  26. }
  27. private List<Guid> _selected = new List<Guid>();
  28. public void Select(ILookupShell shell)
  29. {
  30. foreach (var _item in Items)
  31. _item.Selected = _item == shell;
  32. }
  33. public Color Selected { get; set; }
  34. public Color Background { get; set; }
  35. }
  36. }