using System; using InABox.Core; namespace Comal.Classes { [UserTracking(typeof(Qualification))] public class EmployeeQualification : Entity, IRemotable, IPersistent, IManyToMany, ILicense, IExportable, IImportable { [EditorSequence(0)] [EntityRelationship(DeleteAction.Cascade)] public EmployeeLink Employee { get; set; } [EditorSequence(1)] [EntityRelationship(DeleteAction.Cascade)] public QualificationLink Qualification { get; set; } [EditorSequence(2)] public string QualificationNumber { get; set; } [DateEditor] [EditorSequence(3)] public DateTime Qualified { get; set; } [DateEditor] [EditorSequence(4)] public DateTime Expiry { get; set; } [EditorSequence(5)] public ImageDocumentLink FrontPhoto { get; set; } [EditorSequence(6)] public ImageDocumentLink BackPhoto { get; set; } [TimestampEditor] [EditorSequence(7)] public DateTime Verified { get; set; } protected override void DoPropertyChanged(string name, object? before, object? after) { base.DoPropertyChanged(name, before, after); if (name.Equals(nameof(Qualified))) Expiry = CalculateExpiry((DateTime)after, Qualification.Renewal, Qualification.Period, Expiry); } public DateTime CalculateExpiry(DateTime start, QualificationRenewal renewal, int period, DateTime expiry) { if (renewal == QualificationRenewal.Permanent) return DateTime.MaxValue; if (renewal == QualificationRenewal.Days) return start.AddDays(period); if (renewal == QualificationRenewal.Weeks) return start.AddDays(period * 7); if (renewal == QualificationRenewal.Months) return start.AddMonths(period); if (renewal == QualificationRenewal.Years) return start.AddYears(period); return expiry.Equals(DateTime.MaxValue) || expiry.Equals(DateTime.MinValue) ? DateTime.Today : expiry; } } }