AssignmentListDataModel.cs 3.9 KB

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