AssignmentShell.cs 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using Comal.Classes;
  4. using InABox.Core;
  5. using Xamarin.Forms;
  6. namespace comal.timesheets
  7. {
  8. public class AssignmentShell : Shell<AssignmentModel, Assignment>
  9. {
  10. static AssignmentShell()
  11. {
  12. Columns.Map(nameof(Id), x => x.ID)
  13. .Map(nameof(Number), x => x.Number)
  14. .Map(nameof(Title), x => x.Title)
  15. .Map(nameof(EmployeeId), x => x.EmployeeLink.ID)
  16. .Map(nameof(JobID), x => x.JobLink.ID)
  17. .Map(nameof(JobNumber), x => x.JobLink.JobNumber)
  18. .Map(nameof(JobName), x => x.JobLink.Name)
  19. .Map(nameof(TaskID), x => x.Task.ID)
  20. .Map(nameof(TaskNumber), x => x.Task.Number)
  21. .Map(nameof(TaskName), x => x.Task.Title)
  22. .Map(nameof(Notes), x => x.Description)
  23. .Map(nameof(_date), x => x.Date)
  24. .Map(nameof(_bookedstart), x => x.Booked.Start)
  25. .Map(nameof(_bookedfinish), x => x.Booked.Finish)
  26. .Map(nameof(_actualstart), x => x.Actual.Start)
  27. .Map(nameof(_actualfinish), x => x.Actual.Finish)
  28. .Map(nameof(_completed), x => x.Completed)
  29. .Map(nameof(_color), x => x.ActivityLink.Color)
  30. .Map(nameof(DeliveryID), x=>x.Delivery.ID);
  31. }
  32. public Guid Id => Get<Guid>();
  33. public int Number => Get<int>();
  34. public String Title => Get<String>();
  35. public Guid EmployeeId => Get<Guid>();
  36. public ObservableCollection<object> ResourceIds => new ObservableCollection<object>() { EmployeeId };
  37. public Guid JobID => Get<Guid>();
  38. public string JobNumber => Get<String>();
  39. public string JobName => Get<String>();
  40. public Guid TaskID => Get<Guid>();
  41. public int TaskNumber => Get<int>();
  42. public string TaskName => Get<String>();
  43. public String Subject => string.Format("{0}{1} {2}",
  44. Number,
  45. JobID != Guid.Empty ? $"({JobNumber})" : "",
  46. Title
  47. );
  48. public string Notes => Get<String>();
  49. private DateTime _date => Get<DateTime>();
  50. private TimeSpan _bookedstart => Get<TimeSpan>();
  51. private TimeSpan _bookedfinish => Get<TimeSpan>();
  52. private TimeSpan _actualstart => Get<TimeSpan>();
  53. private TimeSpan _actualfinish => Get<TimeSpan>();
  54. public DateTime StartTime => _date.Add(Assignment.EffectiveTime(_actualstart, _bookedstart).Floor(TimeSpan.FromMinutes(5)));
  55. public DateTime EndTime => _date.Add(Assignment.EffectiveTime(_actualfinish, _bookedfinish).Ceiling(TimeSpan.FromMinutes(5)));
  56. private DateTime _completed => Get<DateTime>();
  57. public bool Completed => !_completed.IsEmpty();
  58. private String _color => Get<String>();
  59. public Color Color
  60. {
  61. get => !String.IsNullOrWhiteSpace(_color) ? Color.FromHex(_color) : Color.Silver;
  62. set => Set<String>(value.ToHex());
  63. }
  64. public Color TextColor => Color.Black;
  65. public Guid DeliveryID => Get<Guid>();
  66. public static Filter<Assignment> MyAssignments =>
  67. new Filter<Assignment>(x => x.EmployeeLink.ID).IsEqualTo(App.Data.Me.ID);
  68. }
  69. }