private EmployeeWorkload GetEmployeeWorkloadForDateRange(Employee employee, DateTimeRange dateRange, WorkloadPeriod periodStep, IDictionary <DateTime, int> workhoursByDate, IDictionary <DateTime, Workload> dailyWorkload)
        {
            var employeeWorkload = new EmployeeWorkload
            {
                Employee = employee
            };

            DateTime dateFrom = dateRange.Begin.Date;

            DateTime dateTo;

            if (periodStep == WorkloadPeriod.Week)
            {
                int daysToSunday = (7 - (int)dateFrom.DayOfWeek) % 7;
                dateTo = dateFrom.AddDays(daysToSunday);
            }
            else if (periodStep == WorkloadPeriod.Month)
            {
                int lastDayOfMonth = DateTime.DaysInMonth(dateFrom.Year, dateFrom.Month);
                dateTo = new DateTime(dateFrom.Year, dateFrom.Month, lastDayOfMonth);
            }
            else
            {
                throw new NotImplementedException($"Обработка периода загрузки {periodStep} не реализована");
            }

            while (dateTo <= dateRange.End.Date)
            {
                EmployeeWorkloadRecord employeeWorkloadRecord = CalculateWorkloadForPeriod(dateFrom, dateTo, dailyWorkload, workhoursByDate);
                employeeWorkload.WorkloadRecords.Add(employeeWorkloadRecord);
                dateFrom = dateTo.AddDays(1);
                if (periodStep == WorkloadPeriod.Week)
                {
                    dateTo = dateTo.AddDays(7);
                }
                else if (periodStep == WorkloadPeriod.Month)
                {
                    dateTo = dateTo.AddMonths(1);
                    int lastDayOfMonth = DateTime.DaysInMonth(dateTo.Year, dateTo.Month);
                    dateTo = new DateTime(dateTo.Year, dateTo.Month, lastDayOfMonth);
                }
            }

            dateTo = dateRange.End.Date;
            if (dateFrom <= dateTo)
            {
                EmployeeWorkloadRecord employeeWorkloadRecord = CalculateWorkloadForPeriod(dateFrom, dateTo, dailyWorkload, workhoursByDate);
                employeeWorkload.WorkloadRecords.Add(employeeWorkloadRecord);
            }

            return(employeeWorkload);
        }
        private IList <EmployeeWorkload> GetEmployeesWorkloadForDateRange(IEnumerable <Employee> employees, DateTimeRange dateRange, WorkloadPeriod periodStep, IDictionary <int, List <ProjectMember> > membershipByEmployees, IDictionary <DateTime, int> workhoursByDate, int projectId)
        {
            var employeeWorkloads = new List <EmployeeWorkload>();

            foreach (var employee in employees)
            {
                if (!membershipByEmployees.TryGetValue(employee.ID, out var projectMemberships))
                {
                    projectMemberships = new List <ProjectMember>();
                }
                var dailyWorkload = GetEmployeeDailyWorkload(projectId, dateRange, projectMemberships, workhoursByDate);

                EmployeeWorkload employeeWorkload = GetEmployeeWorkloadForDateRange(employee, dateRange, periodStep, workhoursByDate, dailyWorkload);
                employeeWorkloads.Add(employeeWorkload);
            }
            return(employeeWorkloads);
        }