AssignmentEditViewModel.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Threading.Tasks;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using InABox.Mobile;
  6. using Point = Xamarin.Forms.Point;
  7. namespace PRS.Mobile
  8. {
  9. public class AssignmentEditViewModel : MobileViewModel<Assignment, AssignmentShell>
  10. {
  11. protected override void DoLoad()
  12. {
  13. Task[] tasks = new Task[]
  14. {
  15. Task.Run(() => Forms.Refresh(true)),
  16. Task.Run(() => Documents.Refresh(true))
  17. };
  18. Task.WaitAll(tasks);
  19. }
  20. public Point Coordinates =>
  21. Item == null
  22. ? new Point()
  23. : new Point
  24. (
  25. Item.Longitude,
  26. Item.Latitude
  27. );
  28. public AssignmentFormModel Forms { get; private set; }
  29. public AssignmentDocumentModel Documents { get; private set; }
  30. public AssignmentEditViewModel()
  31. {
  32. Forms = new AssignmentFormModel(App.Data,
  33. () => new Filter<AssignmentForm>(x => x.Parent.ID).IsEqualTo(Item?.ID ?? CoreUtils.FullGuid)
  34. );
  35. Documents = new AssignmentDocumentModel(App.Data,
  36. () => new Filter<AssignmentDocument>(x => x.EntityLink.ID).IsEqualTo(Item?.ID ?? CoreUtils.FullGuid)
  37. );
  38. }
  39. public override bool IsChanged => Item == null || Item.ID == Guid.Empty || Item.IsChanged();
  40. }
  41. }