JobDocumentSetMileStone.cs 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public class JobDocumentSetMileStoneKanbanCount : CoreAggregate<JobDocumentSetMileStone, JobDocumentSetMileStoneKanban, Guid>
  8. {
  9. public override Expression<Func<JobDocumentSetMileStoneKanban, Guid>> Aggregate => x => x.ID;
  10. public override AggregateCalculation Calculation => AggregateCalculation.Count;
  11. public override Dictionary<Expression<Func<JobDocumentSetMileStoneKanban, object>>, Expression<Func<JobDocumentSetMileStone, object>>> Links =>
  12. new Dictionary<Expression<Func<JobDocumentSetMileStoneKanban, object>>, Expression<Func<JobDocumentSetMileStone, object>>>()
  13. {
  14. { JobDocumentSetMileStoneFile => JobDocumentSetMileStoneFile.Entity.ID, JobDocumentSetMileStone => JobDocumentSetMileStone.ID }
  15. };
  16. public override Filter<JobDocumentSetMileStoneKanban>? Filter =>
  17. new Filter<JobDocumentSetMileStoneKanban>(x => x.Kanban.Completed).IsEqualTo(DateTime.MinValue);
  18. }
  19. public class JobDocumentSetMileStoneFileCount : CoreAggregate<JobDocumentSetMileStone, JobDocumentSetMileStoneFile, Guid>
  20. {
  21. public override Expression<Func<JobDocumentSetMileStoneFile, Guid>> Aggregate => x => x.ID;
  22. public override AggregateCalculation Calculation => AggregateCalculation.Count;
  23. public override Dictionary<Expression<Func<JobDocumentSetMileStoneFile, object>>, Expression<Func<JobDocumentSetMileStone, object>>> Links =>
  24. new Dictionary<Expression<Func<JobDocumentSetMileStoneFile, object>>, Expression<Func<JobDocumentSetMileStone, object>>>()
  25. {
  26. { JobDocumentSetMileStoneFile => JobDocumentSetMileStoneFile.EntityLink.ID, JobDocumentSetMileStone => JobDocumentSetMileStone.ID }
  27. };
  28. }
  29. [Caption("Milestones")]
  30. public class JobDocumentSetMileStone : Entity, IRemotable, IPersistent, IOneToMany<JobDocumentSet>, IJobDocumentSetMileStone, ILicense<ProjectManagementLicense>
  31. {
  32. [EntityRelationship(DeleteAction.Cascade)]
  33. [NullEditor]
  34. public JobDocumentSetLink DocumentSet { get; set; }
  35. [EntityRelationship(DeleteAction.Cascade)]
  36. [NullEditor]
  37. [EditorSequence(1)]
  38. public JobDocumentSetMileStoneTypelink Type { get; set; }
  39. [CodeEditor(Visible = Visible.Default, Editable = Editable.Enabled)]
  40. [EditorSequence(2)]
  41. public String Revision { get; set; }
  42. [EditorSequence(3)]
  43. public EmployeeLink Employee { get; set; }
  44. [EnumLookupEditor(typeof(JobDocumentSetMileStoneStatus))]
  45. [EditorSequence(4)]
  46. public JobDocumentSetMileStoneStatus Status { get; set; }
  47. [NotesEditor]
  48. [EditorSequence(5)]
  49. public String[] Notes { get; set; }
  50. [TextBoxEditor]
  51. [EditorSequence(6)]
  52. public String Watermark { get; set; }
  53. [DateTimeEditor(Editable = Editable.Enabled)]
  54. [EditorSequence(6)]
  55. public DateTime Due { get; set; }
  56. [Obsolete("Replaced with Submitted", true)]
  57. public DateTime Issued { get; set; }
  58. [DateTimeEditor(Editable = Editable.Disabled)]
  59. [EditorSequence(7)]
  60. public DateTime Submitted { get; set; }
  61. [DateTimeEditor(Editable = Editable.Enabled)]
  62. [EditorSequence(8)]
  63. public DateTime Expected { get; set; }
  64. [DateTimeEditor(Editable = Editable.Disabled)]
  65. [EditorSequence(9)]
  66. public DateTime Closed { get; set; }
  67. [NullEditor]
  68. [Aggregate(typeof(JobDocumentSetMileStoneFileCount))]
  69. public int Attachments { get; set; }
  70. [NullEditor]
  71. [Aggregate(typeof(JobDocumentSetMileStoneKanbanCount))]
  72. public int Kanbans { get; set; }
  73. protected override void Init()
  74. {
  75. base.Init();
  76. Status = JobDocumentSetMileStoneStatus.NotStarted;
  77. DocumentSet = new JobDocumentSetLink();
  78. Type = new JobDocumentSetMileStoneTypelink();
  79. Employee = new EmployeeLink();
  80. }
  81. protected override void DoPropertyChanged(string name, object before, object after)
  82. {
  83. base.DoPropertyChanged(name, before, after);
  84. if (String.Equals(name, "Status"))
  85. {
  86. JobDocumentSetMileStoneStatus status = (JobDocumentSetMileStoneStatus)after;
  87. switch (status)
  88. {
  89. case JobDocumentSetMileStoneStatus.InProgress:
  90. case JobDocumentSetMileStoneStatus.OnHold:
  91. case JobDocumentSetMileStoneStatus.InfoRequired:
  92. Submitted = DateTime.MinValue;
  93. Closed = DateTime.MinValue;
  94. break;
  95. case JobDocumentSetMileStoneStatus.Submitted:
  96. Submitted = Submitted.IsEmpty() ? DateTime.Now : Submitted;
  97. Closed = DateTime.MinValue;
  98. break;
  99. case JobDocumentSetMileStoneStatus.Approved:
  100. case JobDocumentSetMileStoneStatus.Rejected:
  101. case JobDocumentSetMileStoneStatus.Cancelled:
  102. Submitted = Submitted.IsEmpty() ? DateTime.Now : Submitted;
  103. Closed = Closed.IsEmpty() ? DateTime.Now : Closed;
  104. break;
  105. }
  106. }
  107. }
  108. }
  109. }