public IList<ProjectCalendarVO> ListAllProjectCalendar(List<DateTime> dateRange, int? divisionFilter, int? equipmentTypeFilter, int? equipmentFilter, int? employeeFilter, int? customerFilter, int? jobFilter, int? jobActionFilter)
        {
            #region [ Raw Data Load ]

            DateTime beginDate = dateRange[0];
            DateTime endDate = dateRange[dateRange.Count - 1].AddDays(1).AddSeconds(-1);
            List<ProjectCalendarVO> calendarList = new List<ProjectCalendarVO>();

            List<CS_View_ProjectCalendar_Allocation> allocationList = _projectCalendarAllocationRepository.ListAll(e =>
                ((jobFilter.HasValue && e.JobID == jobFilter.Value) || (!jobFilter.HasValue)) &&
                ((jobActionFilter.HasValue && e.JobActionID == jobActionFilter.Value) || (!jobActionFilter.HasValue)) &&
                ((divisionFilter.HasValue && e.JobDivisionID == divisionFilter.Value) || (!divisionFilter.HasValue)) &&
                ((equipmentTypeFilter.HasValue && e.EquipmentTypeID.HasValue && e.EquipmentTypeID.Value == equipmentTypeFilter.Value) || (!equipmentTypeFilter.HasValue)) &&
                ((equipmentFilter.HasValue && e.EquipmentID.HasValue && e.EquipmentID.Value == equipmentFilter.Value) || (!equipmentFilter.HasValue)) &&
                ((employeeFilter.HasValue && e.EmployeeID.HasValue && e.EmployeeID.Value == employeeFilter.Value) || (!employeeFilter.HasValue)) &&
                ((customerFilter.HasValue && e.CustomerID == customerFilter.Value) || (!customerFilter.HasValue)) &&

                ((beginDate <= e.LastModification && endDate >= e.LastModification) || (e.PresetInfoDate.HasValue && beginDate <= e.PresetInfoDate && endDate >= e.PresetInfoDate))
                ).ToList();

            List<CS_View_ProjectCalendar_Reserved> reservedList = _projectCalendarReservedRepository.ListAll(e =>
                ((jobFilter.HasValue && e.JobID == jobFilter.Value) || (!jobFilter.HasValue)) &&
                ((jobActionFilter.HasValue && e.JobActionID == jobActionFilter.Value) || (!jobActionFilter.HasValue)) &&
                ((divisionFilter.HasValue && e.JobDivisionID == divisionFilter.Value) || (!divisionFilter.HasValue)) &&
                ((equipmentTypeFilter.HasValue && e.EquipmentTypeID.HasValue && e.EquipmentTypeID.Value == equipmentTypeFilter.Value) || (!equipmentTypeFilter.HasValue)) &&
                ((employeeFilter.HasValue && e.EmployeeID.HasValue && e.EmployeeID.Value == employeeFilter.Value) || (!employeeFilter.HasValue)) &&
                ((customerFilter.HasValue && e.CustomerID == customerFilter.Value) || (!customerFilter.HasValue)) &&

                ((beginDate <= e.LastModification && endDate >= e.LastModification) || (e.PresetInfoDate.HasValue && beginDate <= e.PresetInfoDate && endDate >= e.PresetInfoDate))
                ).ToList();

            List<CS_View_ProjectCalendar_CallLog> callLogList = _projectCalendarCallLogRepository.ListAll(e =>
                ((jobFilter.HasValue && e.JobID == jobFilter.Value) || (!jobFilter.HasValue)) &&

                ((jobActionFilter.HasValue && e.JobActionID == jobActionFilter.Value) || (!jobActionFilter.HasValue)) &&
                ((divisionFilter.HasValue && e.JobDivisionID == divisionFilter.Value) || (!divisionFilter.HasValue)) &&
                ((equipmentTypeFilter.HasValue && e.EquipmentTypeID.HasValue && e.EquipmentTypeID.Value == equipmentTypeFilter.Value) || (!equipmentTypeFilter.HasValue)) &&
                ((equipmentFilter.HasValue && e.EquipmentID.HasValue && e.EquipmentID.Value == equipmentFilter.Value) || (!equipmentFilter.HasValue)) &&
                ((employeeFilter.HasValue && e.EmployeeID.HasValue && e.EmployeeID.Value == employeeFilter.Value) || (!employeeFilter.HasValue)) &&
                ((customerFilter.HasValue && e.CustomerID == customerFilter.Value) || (!customerFilter.HasValue)) &&

                ((beginDate <= e.LastModification && endDate >= e.LastModification) || (e.PresetInfoDate.HasValue && beginDate <= e.PresetInfoDate && endDate >= e.PresetInfoDate))
                ).OrderBy(e => e.JobDivisionID).ThenBy(e => e.JobID).ThenBy(e => e.CallLogID).ToList();

            List<int> jobIDList = allocationList.Select(e => e.JobID).Distinct().ToList();
            jobIDList.AddRange(reservedList.Select(e => e.JobID).Distinct().ToList());
            jobIDList.AddRange(callLogList.Select(e => e.JobID).Distinct().ToList());
            jobIDList = jobIDList.Distinct().ToList();

            //IList<CS_Job_JobStatus> jobStatusHitory = _jobStatusHistoryRepository.ListAll(e => (e.JobStartDate.HasValue || e.JobCloseDate.HasValue) && jobIDList.Contains(e.JobID));
            IList<CS_Job_JobStatus> jobStatusHitory = _jobStatusHistoryRepository.ListAll(e => jobIDList.Contains(e.JobID));

            List<int> removeJobIDList = new List<int>();

            for (int i = 0; i < jobIDList.Count; i++)
            {
                int jobID = jobIDList[i];

                IList<CS_Job_JobStatus> jobStatusHitoryByJob = jobStatusHitory.Where(e => e.JobID == jobID).ToList();

                if (null == jobStatusHitoryByJob || jobStatusHitoryByJob.Count == 0 || !JobHasAnyDateInTheRange(jobStatusHitoryByJob, dateRange))
                {
                    allocationList.RemoveAll(w => w.JobID == jobID);
                    reservedList.RemoveAll(w => w.JobID == jobID);
                    callLogList.RemoveAll(w => w.JobID == jobID);
                }

            }

            List<int> divisionIDList = allocationList.Select(e => e.JobDivisionID).Distinct().ToList();
            divisionIDList.AddRange(reservedList.Select(e => e.JobDivisionID).Distinct().ToList());
            divisionIDList.AddRange(callLogList.Select(e => e.JobDivisionID).Distinct().ToList());
            divisionIDList = divisionIDList.Distinct().ToList();

            IList<CS_Division> divs = _divisionRepository.ListAll();

            #endregion

            #region [ Date Range Loop ]

            for (int dateIndex = 0; dateIndex < dateRange.Count; dateIndex++)
            {
                DateTime date = dateRange[dateIndex];

                #region [ Division Loop ]

                for (int divisionIndex = 0; divisionIndex < divisionIDList.Count; divisionIndex++)
                {
                    int divisionID = divisionIDList[divisionIndex];
                    IList<CS_View_ProjectCalendar_Allocation> jobListAllocation = allocationList.Where(e => e.JobDivisionID == divisionID).ToList();
                    IList<CS_View_ProjectCalendar_Reserved> jobListReserved = reservedList.Where(e => e.JobDivisionID == divisionID).ToList();
                    IList<CS_View_ProjectCalendar_CallLog> jobListCallLog = callLogList.Where(e => e.JobDivisionID == divisionID).ToList();
                    List<int> jobCallLogIDList = jobListCallLog.Select(e => e.JobID).Distinct().ToList();
                    CS_Division div = divs.FirstOrDefault(e => e.ID == divisionID);
                    ProjectCalendarVO currentDivision = calendarList.FirstOrDefault(e => e.DivisionID == divisionID && e.CalendarDate == date);
                    string divName = string.Empty;

                    if (null != div)
                        divName = div.Name;

                    if (null == currentDivision)
                    {
                        currentDivision = new ProjectCalendarVO()
                        {
                            CalendarDate = date,
                            DivisionName = divName,
                            DivisionID = divisionID
                        };

                        calendarList.Add(currentDivision);
                    }

                    #region [ Job Allocation Loop ]

                    for (int jobIndex = 0; jobIndex < jobListAllocation.Count; jobIndex++)
                    {
                        CS_View_ProjectCalendar_Allocation job = jobListAllocation[jobIndex];
                        IList<CS_Job_JobStatus> jobStatusHitoryByJobID = jobStatusHitory.Where(e => e.JobID == job.JobID).ToList();
                        JobCalendarVO currentJob = currentDivision.JobCalendarList.FirstOrDefault(e => e.JobID == job.JobID);
                        bool activeAtDate = JobWasActiveAtDate(jobStatusHitoryByJobID, date);

                        if (null == currentJob)
                        {
                            currentJob = new JobCalendarVO()
                                {
                                    Job = job.PrefixedNumber,
                                    PaintDate = activeAtDate,
                                    JobID = job.JobID,
                                    CustomerName = job.Customer,
                                    DivisionName = job.JobDivisionName,
                                    CityName = job.JobCityName,
                                    StateName = job.JobStateName,
                                    StatusName = job.JobStatusName,
                                    ActionName = job.JobActionName
                                };

                            currentDivision.JobCalendarList.Add(currentJob);
                        }

                        #region [ Resource Adding ]

                        if (job.ResourceEndDateTime.HasValue && job.ResourceStartDateTime.HasValue)
                        {
                            if (date.Date >= job.ResourceStartDateTime.Value.Date && date.Date <= job.ResourceEndDateTime.Value.Date)
                            {
                                if (job.EmployeeID.HasValue)
                                {
                                    ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EmployeeID == job.EmployeeID);

                                    if (null == resource)
                                    {
                                        resource = new ResourceVO()
                                        {
                                            EmployeeID = job.EmployeeID,
                                            EmployeeName = job.EmployeeName,
                                            ResourceColor = (int)Globals.ProjectCalendar.ResourceType.AddEmployee
                                        };

                                        currentJob.ResourceList.Add(resource);
                                    }

                                    resource.EstimatedWork = true;
                                }
                                else if (job.EquipmentID.HasValue)
                                {
                                    ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EquipmentID == job.EquipmentID);

                                    if (null == resource)
                                    {
                                        resource = new ResourceVO()
                                        {
                                            EquipmentID = job.EquipmentID,
                                            EquipmentName = job.EquipmentName,
                                            ResourceColor = (int)Globals.ProjectCalendar.ResourceType.AddEquipment
                                        };

                                        currentJob.ResourceList.Add(resource);
                                    }

                                    resource.EstimatedWork = true;
                                }
                            }
                            else if ((beginDate <= job.ResourceStartDateTime.Value.Date && endDate >= job.ResourceStartDateTime.Value.Date) || (beginDate <= job.ResourceEndDateTime.Value.Date && endDate >= job.ResourceEndDateTime.Value.Date))
                            {
                                if (job.EmployeeID.HasValue)
                                {
                                    ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EmployeeID == job.EmployeeID);

                                    if (null == resource)
                                    {
                                        resource = new ResourceVO()
                                        {
                                            EmployeeID = job.EmployeeID,
                                            EmployeeName = job.EmployeeName,
                                            ResourceColor = (int)Globals.ProjectCalendar.ResourceType.AddEmployee
                                        };

                                        currentJob.ResourceList.Add(resource);
                                    }

                                    resource.EstimatedWork = false;
                                }
                                else if (job.EquipmentID.HasValue)
                                {
                                    ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EquipmentID == job.EquipmentID);

                                    if (null == resource)
                                    {
                                        resource = new ResourceVO()
                                        {
                                            EquipmentID = job.EquipmentID,
                                            EquipmentName = job.EquipmentName,
                                            ResourceColor = (int)Globals.ProjectCalendar.ResourceType.AddEquipment
                                        };

                                        currentJob.ResourceList.Add(resource);
                                    }

                                    resource.EstimatedWork = false;
                                }
                            }
                        }

                        #endregion
                    }

                    #endregion

                    #region [ Job Reserved Loop ]

                    for (int jobIndex = 0; jobIndex < jobListReserved.Count; jobIndex++)
                    {
                        CS_View_ProjectCalendar_Reserved job = jobListReserved[jobIndex];
                        IList<CS_Job_JobStatus> jobStatusHitoryByJobID = jobStatusHitory.Where(e => e.JobID == job.JobID).ToList();
                        JobCalendarVO currentJob = currentDivision.JobCalendarList.FirstOrDefault(e => e.JobID == job.JobID);
                        bool activeAtDate = JobWasActiveAtDate(jobStatusHitoryByJobID, date);

                        if (null == currentJob)
                        {
                            currentJob = new JobCalendarVO()
                            {
                                Job = job.PrefixedNumber,
                                PaintDate = activeAtDate,
                                JobID = job.JobID,
                                CustomerName = job.Customer,
                                DivisionName = job.JobDivisionName,
                                CityName = job.JobCityName,
                                StateName = job.JobStateName,
                                StatusName = job.JobStatusName,
                                ActionName = job.JobActionName
                            };

                            currentDivision.JobCalendarList.Add(currentJob);
                        }

                        #region [ Resource Adding ]

                        if (job.ResourceEndDateTime.HasValue && job.ResourceStartDateTime.HasValue)
                        {
                            if (date.Date >= job.ResourceStartDateTime.Value.Date && date.Date <= job.ResourceEndDateTime.Value.Date)
                            {
                                if (job.EmployeeID.HasValue)
                                {
                                    ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EmployeeID == job.EmployeeID);

                                    if (null == resource)
                                    {
                                        resource = new ResourceVO()
                                        {
                                            EmployeeID = job.EmployeeID,
                                            EmployeeName = job.EmployeeName,
                                            ResourceColor = (int)Globals.ProjectCalendar.ResourceType.ReservedEmployee
                                        };

                                        currentJob.ResourceList.Add(resource);
                                    }

                                    resource.Reserved = true;
                                }
                                else if (job.EquipmentTypeID.HasValue)
                                {
                                    ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EquipmentTypeID == job.EquipmentTypeID);

                                    if (null == resource)
                                    {
                                        resource = new ResourceVO()
                                        {
                                            EquipmentTypeID = job.EquipmentTypeID,
                                            EquipmentTypeName = job.EquipmentTypeName,
                                            ResourceColor = (int)Globals.ProjectCalendar.ResourceType.ReservedEquipment
                                        };

                                        currentJob.ResourceList.Add(resource);
                                    }

                                    resource.Reserved = true;
                                }
                            }
                            else if ((beginDate <= job.ResourceStartDateTime.Value.Date && endDate >= job.ResourceStartDateTime.Value.Date) || (beginDate <= job.ResourceEndDateTime.Value.Date && endDate >= job.ResourceEndDateTime.Value.Date))
                            {
                                if (job.EmployeeID.HasValue)
                                {
                                    ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EmployeeID == job.EmployeeID);

                                    if (null == resource)
                                    {
                                        resource = new ResourceVO()
                                        {
                                            EmployeeID = job.EmployeeID,
                                            EmployeeName = job.EmployeeName,
                                            ResourceColor = (int)Globals.ProjectCalendar.ResourceType.ReservedEmployee
                                        };

                                        currentJob.ResourceList.Add(resource);
                                    }

                                    resource.Reserved = false;
                                }
                                else if (job.EquipmentTypeID.HasValue)
                                {
                                    ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EquipmentTypeID == job.EquipmentTypeID);

                                    if (null == resource)
                                    {
                                        resource = new ResourceVO()
                                        {
                                            EquipmentTypeID = job.EquipmentTypeID,
                                            EquipmentTypeName = job.EquipmentTypeName,
                                            ResourceColor = (int)Globals.ProjectCalendar.ResourceType.ReservedEquipment
                                        };

                                        currentJob.ResourceList.Add(resource);
                                    }

                                    resource.Reserved = false;
                                }
                            }
                        }

                        #endregion
                    }

                    #endregion

                    #region [ Job Call Log Loop ]

                    for (int jobIndex = 0; jobIndex < jobCallLogIDList.Count; jobIndex++)
                    {
                        int jobID = jobCallLogIDList[jobIndex];
                        JobCalendarVO currentJob = currentDivision.JobCalendarList.FirstOrDefault(e => e.JobID == jobID);

                        if (null == currentJob)
                        {
                            IList<CS_Job_JobStatus> jobStatusHitoryByJobID = jobStatusHitory.Where(e => e.JobID == jobID).ToList();
                            bool activeAtDate = JobWasActiveAtDate(jobStatusHitoryByJobID, date);
                            CS_View_ProjectCalendar_CallLog job = jobListCallLog.FirstOrDefault(e => e.JobID == jobID);

                            currentJob = new JobCalendarVO()
                            {
                                Job = job.PrefixedNumber,
                                PaintDate = activeAtDate,
                                JobID = job.JobID,
                                CustomerName = job.Customer,
                                DivisionName = job.JobDivisionName,
                                CityName = job.JobCityName,
                                StateName = job.JobStateName,
                                StatusName = job.JobStatusName,
                                ActionName = job.JobActionName
                            };

                            calendarList[calendarList.Count - 1].JobCalendarList.Add(currentJob);
                        }

                        IList<CS_View_ProjectCalendar_CallLog> employeeCallLogHitoryByJobID = jobListCallLog.Where(e => e.EmployeeID.HasValue && e.JobID == jobID).ToList();
                        IList<CS_View_ProjectCalendar_CallLog> equipmentCallLogHitoryByJobID = jobListCallLog.Where(e => e.EquipmentID.HasValue && e.JobID == jobID).ToList();
                        List<int> employeeIDList = employeeCallLogHitoryByJobID.Select(e => e.EmployeeID.Value).Distinct().ToList();
                        List<int> equipmentIDList = equipmentCallLogHitoryByJobID.Select(e => e.EquipmentID.Value).Distinct().ToList();

                        #region [ Employee Adding ]

                        for (int employeeIndex = 0; employeeIndex < employeeIDList.Count; employeeIndex++)
                        {
                            int employeeID = employeeIDList[employeeIndex];
                            IList<CS_View_ProjectCalendar_CallLog> employeeCallLogHitoryByEmployee = employeeCallLogHitoryByJobID.Where(e => e.EmployeeID.Value == employeeID).ToList();

                            bool activeAtDateResource = ResourceWasWorkingAtDate(employeeCallLogHitoryByEmployee, date);

                            ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EmployeeID == employeeID);

                            if (null == resource)
                            {
                                CS_View_ProjectCalendar_CallLog currentRes = employeeCallLogHitoryByEmployee.FirstOrDefault();
                                resource = new ResourceVO()
                                {
                                    EmployeeID = currentRes.EmployeeID,
                                    EmployeeName = currentRes.EmployeeName,
                                    ResourceColor = (int)Globals.ProjectCalendar.ResourceType.AddEmployee
                                };

                                if ((beginDate <= currentRes.ResourceStartDateTime.Value.Date && endDate >= currentRes.ResourceStartDateTime.Value.Date) || (beginDate <= currentRes.ResourceEndDateTime.Value.Date && endDate >= currentRes.ResourceEndDateTime.Value.Date))
                                    currentJob.ResourceList.Add(resource);
                            }

                            resource.Worked = activeAtDateResource;

                        }

                        #endregion

                        #region [ Equipment Adding ]

                        for (int equipmentIndex = 0; equipmentIndex < equipmentIDList.Count; equipmentIndex++)
                        {
                            int equipmentID = equipmentIDList[equipmentIndex];
                            IList<CS_View_ProjectCalendar_CallLog> equipmentCallLogHitoryByEquipment = equipmentCallLogHitoryByJobID.Where(e => e.EquipmentID.Value == equipmentID).ToList();
                            bool activeAtDateResource = ResourceWasWorkingAtDate(equipmentCallLogHitoryByEquipment, date);

                            ResourceVO resource = currentJob.ResourceList.FirstOrDefault(e => e.EquipmentID == equipmentID);

                            if (null == resource)
                            {
                                CS_View_ProjectCalendar_CallLog currentRes = equipmentCallLogHitoryByEquipment.FirstOrDefault();
                                resource = new ResourceVO()
                                {
                                    EquipmentID = currentRes.EquipmentID,
                                    EquipmentName = currentRes.EquipmentName,
                                    ResourceColor = (int)Globals.ProjectCalendar.ResourceType.AddEquipment
                                };

                                if (currentRes.ResourceStartDateTime.HasValue)
                                {
                                    if ((beginDate <= currentRes.ResourceStartDateTime.Value.Date && endDate >= currentRes.ResourceStartDateTime.Value.Date) || (beginDate <= currentRes.ResourceEndDateTime.Value.Date && endDate >= currentRes.ResourceEndDateTime.Value.Date))
                                        currentJob.ResourceList.Add(resource);
                                }
                            }

                            resource.Worked = activeAtDateResource;

                        }

                        #endregion
                    }

                    #endregion
                }

                #endregion
            }

            #endregion

            return calendarList;
        }
        public List<ProjectCalendarVO> ReturnVO()
        {
            List<ResourceVO> resourceList1 = new List<ResourceVO>();
            List<ResourceVO> resourceList2 = new List<ResourceVO>();
            List<JobCalendarVO> jobCalendarList = new List<JobCalendarVO>();
            List<ProjectCalendarVO> projectCalendarList = new List<ProjectCalendarVO>();

            ResourceVO res1 = new ResourceVO()
            {
                EquipmentID = 1,
                EquipmentName = "Truck1",
                EstimatedWork = true,
                Worked = true
            };

            ResourceVO res2 = new ResourceVO()
            {
                EmployeeID = 1,
                EmployeeName = "John Doe",
                EstimatedWork = false,
                Worked = true
            };

            resourceList1.Add(res1);
            resourceList1.Add(res2);

            JobCalendarVO jobVO = new JobCalendarVO()
            {
                Job = "Job1",
                JobID = 1,
                PaintDate = true,
                ResourceList = resourceList1
            };

            jobCalendarList.Add(jobVO);

            ProjectCalendarVO vo = new ProjectCalendarVO()
            {
                CalendarDate = new DateTime(2011, 12, 01),
                DivisionID = 1,
                DivisionName = "Div1",
                JobCalendarList = jobCalendarList
            };

            ProjectCalendarVO vo2 = new ProjectCalendarVO()
            {
                CalendarDate = new DateTime(2011, 12, 02),
                DivisionID = 1,
                DivisionName = "Div1",
                JobCalendarList = jobCalendarList
            };

            projectCalendarList.Add(vo);
            projectCalendarList.Add(vo2);

            return projectCalendarList;
        }