private static EmployeeReport ToEmployeeReport(EmployeeEntity employee, DateTime?beginDate = null, DateTime?endDate = null) { var actualBeginDate = beginDate ?? DateTime.MinValue; var actualEndDate = endDate ?? DateTime.MaxValue; var employeeReport = new EmployeeReport { Employee = employee.ToEmployeeModel(), TimeRecords = employee.TimeRecords .Where(i => actualBeginDate <= i.Date && i.Date <= actualEndDate) .Select(timeRecord => timeRecord.ToTimeRecord()) .ToArray(), Resources = employee.SoldResources .Select(i => i.SoldResource) .Select(resource => resource.ToResourceModel(beginDate, endDate)) .ToArray(), ProjectResources = employee.SoldResources.Select(resource => new ProjectResource { ProjectName = resource.SoldResource.Project.Name, Resource = resource.SoldResource.ToResourceModel(beginDate, endDate) }) }; employeeReport.TakenTime = employeeReport.ProjectResources.Sum(i => i.Resource.TakenTime); employeeReport.TakenMoney = employeeReport.ProjectResources.Sum(i => i.Resource.TakenMoney); return(employeeReport); }