using System; using System.Collections.Generic; using System.Linq.Expressions; using InABox.Core; namespace Comal.Classes { public interface IEmployeeAlert : IEntity { EmployeeLink Employee { get; set; } } public class EmployeeAlertUnionGenerator : AutoEntityUnionGenerator { protected override void Configure() { AddTable() .AliasField(ea => ea.Employee.ID, e => e.ID); } public override bool Distinct => false; public override Column[] IDColumns => new Column[] { new Column(x => x.Employee.ID), }; } [UserTracking(typeof(Employee))] [AutoEntity(typeof(EmployeeAlertUnionGenerator))] public class EmployeeAlert : Entity, IEmployeeAlert, IRemotable, IPersistent, IOneToMany, ILicense { public EmployeeLink Employee { get; set; } private class NotificationsAggregate : ComplexFormulaGenerator { public override IComplexFormulaNode GetFormula() => Aggregate( AggregateCalculation.Count, x =>x.Constant(1), new Filter(x => x.Closed).IsEqualTo(DateTime.MinValue)) .WithLink(x => x.Employee.ID, x => x.ID); } [ComplexFormula(typeof(NotificationsAggregate))] [IntegerEditor(Editable = Editable.Hidden)] public int Notifications { get; set; } private class TasksAggregate : ComplexFormulaGenerator { public override IComplexFormulaNode GetFormula() => Aggregate( AggregateCalculation.Count, x =>x.Constant(1), new Filter(x => x.Status).IsEqualTo(KanbanStatus.Complete)) .WithLink(x => x.EmployeeLink.ID, x => x.ID); } [ComplexFormula(typeof(TasksAggregate))] [IntegerEditor(Editable = Editable.Hidden)] public int Tasks { get; set; } private class QualificationsAggregate : ComplexFormulaGenerator { public override IComplexFormulaNode GetFormula() => Aggregate( AggregateCalculation.Count, x =>x.Constant(1), new Filter(x => x.Qualified).IsEqualTo(DateTime.MinValue) .Or(x=>x.FrontPhoto.ID).IsEqualTo(Guid.Empty) .Or(x=>x.Expiry).IsLessThan(FilterConstant.Today)) .WithLink(x => x.Employee.ID, x => x.ID); } [ComplexFormula(typeof(QualificationsAggregate))] [IntegerEditor(Editable = Editable.Hidden)] public int Qualifications { get; set; } private class DigitalFormsAggregate : ComplexFormulaGenerator { public override IComplexFormulaNode GetFormula() => Aggregate( AggregateCalculation.Count, x =>x.Constant(1), new Filter(x => x.FormCompleted).IsEqualTo(DateTime.MinValue) ) .WithLink(x => x.Parent.ID, x => x.ID); } [ComplexFormula(typeof(QualificationsAggregate))] [IntegerEditor(Editable = Editable.Hidden)] public int DigitalForms { get; set; } } }