EmployeeAlert.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq.Expressions;
  4. using InABox.Core;
  5. namespace Comal.Classes
  6. {
  7. public interface IEmployeeAlert : IEntity
  8. {
  9. EmployeeLink Employee { get; set; }
  10. }
  11. public class EmployeeAlertUnionGenerator : AutoEntityUnionGenerator<IEmployeeAlert>
  12. {
  13. protected override void Configure()
  14. {
  15. AddTable<Employee>()
  16. .AliasField(ea => ea.Employee.ID, e => e.ID);
  17. }
  18. public override bool Distinct => false;
  19. public override Column<IEmployeeAlert>[] IDColumns => new Column<IEmployeeAlert>[]
  20. {
  21. new Column<IEmployeeAlert>(x => x.Employee.ID),
  22. };
  23. }
  24. [UserTracking(typeof(Employee))]
  25. [AutoEntity(typeof(EmployeeAlertUnionGenerator))]
  26. public class EmployeeAlert : Entity, IEmployeeAlert, IRemotable, IPersistent, IOneToMany<Employee>,
  27. ILicense<CoreLicense>
  28. {
  29. public EmployeeLink Employee { get; set; }
  30. private class NotificationsAggregate : ComplexFormulaGenerator<EmployeeAlert, int>
  31. {
  32. public override IComplexFormulaNode<EmployeeAlert, int> GetFormula() =>
  33. Aggregate<Notification>(
  34. AggregateCalculation.Count,
  35. x =>x.Constant(1),
  36. new Filter<Notification>(x => x.Closed).IsEqualTo(DateTime.MinValue))
  37. .WithLink(x => x.Employee.ID, x => x.ID);
  38. }
  39. [ComplexFormula(typeof(NotificationsAggregate))]
  40. [IntegerEditor(Editable = Editable.Hidden)]
  41. public int Notifications { get; set; }
  42. private class TasksAggregate : ComplexFormulaGenerator<EmployeeAlert, int>
  43. {
  44. public override IComplexFormulaNode<EmployeeAlert, int> GetFormula() =>
  45. Aggregate<Kanban>(
  46. AggregateCalculation.Count,
  47. x =>x.Constant(1),
  48. new Filter<Kanban>(x => x.Status).IsEqualTo(KanbanStatus.Complete))
  49. .WithLink(x => x.EmployeeLink.ID, x => x.ID);
  50. }
  51. [ComplexFormula(typeof(TasksAggregate))]
  52. [IntegerEditor(Editable = Editable.Hidden)]
  53. public int Tasks { get; set; }
  54. private class QualificationsAggregate : ComplexFormulaGenerator<EmployeeAlert, int>
  55. {
  56. public override IComplexFormulaNode<EmployeeAlert, int> GetFormula() =>
  57. Aggregate<EmployeeQualification>(
  58. AggregateCalculation.Count,
  59. x =>x.Constant(1),
  60. new Filter<EmployeeQualification>(x => x.Qualified).IsEqualTo(DateTime.MinValue)
  61. .Or(x=>x.FrontPhoto.ID).IsEqualTo(Guid.Empty)
  62. .Or(x=>x.Expiry).IsLessThan(FilterConstant.Today))
  63. .WithLink(x => x.Employee.ID, x => x.ID);
  64. }
  65. [ComplexFormula(typeof(QualificationsAggregate))]
  66. [IntegerEditor(Editable = Editable.Hidden)]
  67. public int Qualifications { get; set; }
  68. private class DigitalFormsAggregate : ComplexFormulaGenerator<EmployeeAlert, int>
  69. {
  70. public override IComplexFormulaNode<EmployeeAlert, int> GetFormula() =>
  71. Aggregate<EmployeeForm>(
  72. AggregateCalculation.Count,
  73. x =>x.Constant(1),
  74. new Filter<EmployeeForm>(x => x.FormCompleted).IsEqualTo(DateTime.MinValue)
  75. )
  76. .WithLink(x => x.Parent.ID, x => x.ID);
  77. }
  78. [ComplexFormula(typeof(QualificationsAggregate))]
  79. [IntegerEditor(Editable = Editable.Hidden)]
  80. public int DigitalForms { get; set; }
  81. }
  82. }