using LCU.Library.Internal.IncentiveApiModels.Common; using LCU.Library.Internal.IncentiveApiModels.Entities; namespace LCU.API.Internal.Operations.IncentiveApi.Models; public class EmployeeGoals { public EmployeeGoals(AppUser employee, MonthRange monthRange) { Employee = employee; MonthRange = monthRange; Goals = new Dictionary(); Departments = employee.Departments.Where(dept => dept.StartDate.Date < monthRange.EndTime.Date && (dept.EndDate == null || monthRange.StartTime.Date < dept.EndDate.Value.Date)).ToList(); foreach (var department in Departments) { Goals[department.DepartmentId] = new PerProductGoal(); } GoalAudit = new List(); } public AppUser Employee { get; } public MonthRange MonthRange { get; } public ICollection Departments { get; } public IDictionary Goals { get; } public IEnumerable GoalAudit { get; set; } public void ApplyAll(ICollection goals) { GoalAudit = GoalAudit.Concat(goals); foreach (var goal in goals) { if (Goals.Keys.Contains(goal.DepartmentId)) { Goals[goal.DepartmentId].ProductGoals[goal.Product] += goal.Value; } } } }