AssignmentListDataModel.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using Comal.Classes;
  6. using InABox.Core;
  7. using Xamarin.Forms;
  8. using static Android.InputMethodServices.Keyboard;
  9. namespace comal.timesheets
  10. {
  11. public class AssignmentListDataModel : ListDataModel<Assignment, AssignmentListDataModelItem>
  12. {
  13. public override Columns<Assignment> Columns => new Columns<Assignment>(x => x.ID)
  14. .Add(x => x.Number)
  15. .Add(x => x.Title)
  16. .Add(x => x.Description)
  17. .Add(x => x.Date)
  18. .Add(x => x.Actual.Start)
  19. .Add(x => x.Actual.Finish)
  20. .Add(x => x.Booked.Start)
  21. .Add(x => x.Booked.Finish)
  22. .Add(x => x.ActivityLink.Color)
  23. .Add(x => x.EmployeeLink.ID)
  24. .Add(x => x.JobLink.ID)
  25. .Add(x => x.JobLink.JobNumber)
  26. .Add(x => x.JobLink.Name)
  27. .Add(x => x.Task.ID)
  28. .Add(x => x.Task.Number)
  29. .Add(x => x.Task.Title)
  30. .Add(x => x.Completed);
  31. }
  32. public class AssignmentListDataModelItem : CoreDataModelItem
  33. {
  34. public Guid Id => Row.Get<Assignment, Guid>(c => c.ID);
  35. public int Number => Row.Get<Assignment, int>(c => c.Number);
  36. public Guid EmployeeId => Row.Get<Assignment, Guid>(c => c.EmployeeLink.ID);
  37. public Guid JobID => Row.Get<Assignment, Guid>(c => c.JobLink.ID);
  38. public string JobNumber => Row.Get<Assignment, String>(c => c.JobLink.JobNumber);
  39. public string JobName => Row.Get<Assignment, String>(c => c.JobLink.Name);
  40. public Guid TaskID => Row.Get<Assignment, Guid>(c => c.Task.ID);
  41. public int TaskNumber => Row.Get<Assignment, int>(c => c.Task.Number);
  42. public string TaskName => Row.Get<Assignment, String>(c => c.Task.Title);
  43. public String Subject => string.Format("{0}{1} {2}",
  44. Row.Get<Assignment, int>(c => c.Number),
  45. Row.Get<Assignment, Guid>(c => c.JobLink.ID) != Guid.Empty
  46. ? $"({Row.Get<Assignment, String>(c => c.JobLink.JobNumber)})"
  47. : "",
  48. Row.Get<Assignment, String>(c => c.Title));
  49. public string Notes => Row.Get<Assignment, String>(c => c.Description);
  50. public DateTime StartTime
  51. {
  52. get
  53. {
  54. var startspan = Row.Get<Assignment, TimeSpan>(c => c.Actual.Start);
  55. if (startspan.TotalMinutes != 0)
  56. return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Actual.Start));
  57. else
  58. return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Booked.Start));
  59. }
  60. }
  61. public DateTime EndTime
  62. {
  63. get
  64. {
  65. var finishspan = Row.Get<Assignment, TimeSpan>(c => c.Actual.Finish);
  66. if (finishspan.TotalMinutes != 0)
  67. return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Actual.Finish));
  68. else
  69. return Row.Get<Assignment, DateTime>(c => c.Date).Add(Row.Get<Assignment, TimeSpan>(c => c.Booked.Finish));
  70. }
  71. }
  72. public bool Completed => !Row.Get<Assignment, DateTime>(c => c.Completed).IsEmpty();
  73. public Color Color
  74. {
  75. get
  76. {
  77. var color = Row.Get<Assignment, String>(c => c.ActivityLink.Color);
  78. return !String.IsNullOrWhiteSpace(color)
  79. ? Color.FromHex(color)
  80. : Color.Silver;
  81. }
  82. set { Row.Set<Assignment, String>(c => c.ActivityLink.Color, value.ToHex()); }
  83. }
  84. public Color TextColor => Color.Black;
  85. public ObservableCollection<object> ResourceIds => new ObservableCollection<object>() { Row.Get<Assignment, Guid>(c => c.EmployeeLink.ID) };
  86. }
  87. }