EmployeeQualification.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. using System;
  2. using InABox.Core;
  3. namespace Comal.Classes
  4. {
  5. [UserTracking(typeof(Qualification))]
  6. public class EmployeeQualification : Entity, IRemotable, IPersistent, IManyToMany<Employee, Qualification>, ILicense<HumanResourcesLicense>,
  7. IExportable, IImportable
  8. {
  9. [EditorSequence(0)]
  10. [EntityRelationship(DeleteAction.Cascade)]
  11. public EmployeeLink Employee { get; set; }
  12. [EditorSequence(1)]
  13. [EntityRelationship(DeleteAction.Cascade)]
  14. public QualificationLink Qualification { get; set; }
  15. [EditorSequence(2)]
  16. public string QualificationNumber { get; set; }
  17. [DateEditor]
  18. [EditorSequence(3)]
  19. public DateTime Qualified { get; set; }
  20. [DateEditor]
  21. [EditorSequence(4)]
  22. public DateTime Expiry { get; set; }
  23. [EditorSequence(5)]
  24. public ImageDocumentLink FrontPhoto { get; set; }
  25. [EditorSequence(6)]
  26. public ImageDocumentLink BackPhoto { get; set; }
  27. [TimestampEditor]
  28. [EditorSequence(7)]
  29. public DateTime Verified { get; set; }
  30. protected override void Init()
  31. {
  32. base.Init();
  33. Employee = new EmployeeLink();
  34. Qualification = new QualificationLink();
  35. Verified = DateTime.MinValue;
  36. FrontPhoto = new ImageDocumentLink();
  37. BackPhoto = new ImageDocumentLink();
  38. }
  39. protected override void DoPropertyChanged(string name, object before, object after)
  40. {
  41. base.DoPropertyChanged(name, before, after);
  42. if (name.Equals(nameof(Qualified)))
  43. Expiry = CalculateExpiry((DateTime)after, Qualification.Renewal, Qualification.Period, Expiry);
  44. }
  45. public DateTime CalculateExpiry(DateTime start, QualificationRenewal renewal, int period, DateTime expiry)
  46. {
  47. if (renewal == QualificationRenewal.Permanent)
  48. return DateTime.MaxValue;
  49. if (renewal == QualificationRenewal.Days)
  50. return start.AddDays(period);
  51. if (renewal == QualificationRenewal.Weeks)
  52. return start.AddDays(period * 7);
  53. if (renewal == QualificationRenewal.Months)
  54. return start.AddMonths(period);
  55. if (renewal == QualificationRenewal.Years)
  56. return start.AddYears(period);
  57. return expiry.Equals(DateTime.MaxValue) || expiry.Equals(DateTime.MinValue) ? DateTime.Today : expiry;
  58. }
  59. }
  60. }