| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 | using System;using InABox.Core;namespace Comal.Classes{    [UserTracking(typeof(Qualification))]    public class EmployeeQualification : Entity, IRemotable, IPersistent, IManyToMany<Employee, Qualification>, ILicense<HumanResourcesLicense>,        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 Init()        {            base.Init();            Employee = new EmployeeLink();            Qualification = new QualificationLink();            Verified = DateTime.MinValue;            FrontPhoto = new ImageDocumentLink();            BackPhoto = new ImageDocumentLink();        }        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;        }    }}
 |