AssignmentListDataModel.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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.Actual.Duration)
  20. .Add(x => x.Booked.Start)
  21. .Add(x => x.Booked.Finish)
  22. .Add(x => x.Booked.Duration)
  23. .Add(x => x.ActivityLink.Color)
  24. .Add(x => x.EmployeeLink.ID)
  25. .Add(x => x.JobLink.ID)
  26. .Add(x => x.JobLink.JobNumber)
  27. .Add(x => x.JobLink.Name)
  28. .Add(x => x.Task.ID)
  29. .Add(x => x.Task.Number)
  30. .Add(x => x.Task.Title)
  31. .Add(x => x.Completed);
  32. }
  33. public class AssignmentListDataModelItem : CoreDataModelItem
  34. {
  35. public Guid Id => Row.Get<Assignment, Guid>(c => c.ID);
  36. public int Number => Row.Get<Assignment, int>(c => c.Number);
  37. public Guid EmployeeId => Row.Get<Assignment, Guid>(c => c.EmployeeLink.ID);
  38. public Guid JobID => Row.Get<Assignment, Guid>(c => c.JobLink.ID);
  39. public string JobNumber => Row.Get<Assignment, String>(c => c.JobLink.JobNumber);
  40. public string JobName => Row.Get<Assignment, String>(c => c.JobLink.Name);
  41. public Guid TaskID => Row.Get<Assignment, Guid>(c => c.Task.ID);
  42. public int TaskNumber => Row.Get<Assignment, int>(c => c.Task.Number);
  43. public string TaskName => Row.Get<Assignment, String>(c => c.Task.Title);
  44. public String Subject => string.Format("{0}{1} {2}",
  45. Row.Get<Assignment, int>(c => c.Number),
  46. Row.Get<Assignment, Guid>(c => c.JobLink.ID) != Guid.Empty
  47. ? $"({Row.Get<Assignment, String>(c => c.JobLink.JobNumber)})"
  48. : "",
  49. Row.Get<Assignment, String>(c => c.Title));
  50. public string Notes => Row.Get<Assignment, String>(c => c.Description);
  51. public DateTime StartTime => Row.ToObject<Assignment>().EffectiveStart();
  52. public DateTime EndTime => Row.ToObject<Assignment>().EffectiveFinish();
  53. public bool Completed => !Row.Get<Assignment, DateTime>(c => c.Completed).IsEmpty();
  54. public Color Color
  55. {
  56. get
  57. {
  58. var color = Row.Get<Assignment, String>(c => c.ActivityLink.Color);
  59. return !String.IsNullOrWhiteSpace(color)
  60. ? Color.FromHex(color)
  61. : Color.Silver;
  62. }
  63. set { Row.Set<Assignment, String>(c => c.ActivityLink.Color, value.ToHex()); }
  64. }
  65. public Color TextColor => Color.Black;
  66. public ObservableCollection<object> ResourceIds => new ObservableCollection<object>() { Row.Get<Assignment, Guid>(c => c.EmployeeLink.ID) };
  67. }
  68. }