AssignmentListDataModel.cs 3.1 KB

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