public TaskGridViewModel(IEnumerable <Task> Tasks, IUserRepository UserRepository, string CAMDrawingPath, ICNCMachInfoRepository MachInfoRepository, IEDMDetailRepository EDMDetailRepository, ITaskRepository TaskRepository, IProjectPhaseRepository ProjectPhaseRepository, IMGSettingRepository MGSettingRepository, IWEDMSettingRepository WEDMSettingRepository, ITaskHourRepository TaskHourRepository , ISystemConfigRepository SystemConfigRepo , ITaskTypeRepository TasktypeRepo , IMachinesInfoRepository MachInfoRepo) { ProjectPhase _phase; string _cad, _cam, _workshop, _qc, _planDate; int _phaseID = 0; rows = new List <TaskGridRowModel>(); List <WEDMSetting> _wedmSettings = WEDMSettingRepository.WEDMSettings.ToList(); List <MGSetting> _mgSettings = MGSettingRepository.MGSettings.ToList(); List <User> _users = UserRepository.Users.ToList(); List <ProjectPhase> _pjPhases = ProjectPhaseRepository.ProjectPhases.ToList(); List <TaskHour> _taskhours = TaskHourRepository.TaskHours.ToList(); List <MachinesInfo> _machineInfos = MachInfoRepo.MachinesInfo.ToList(); List <TaskType> _tasktypes = TasktypeRepo.TaskTypes.ToList(); List <CNCMachInfo> _cncmachInfos = MachInfoRepository.CNCMachInfoes.ToList(); List <Task> _tasks = TaskRepository.Tasks.ToList(); List <EDMDetail> _edmDetails = EDMDetailRepository.EDMDetails.ToList(); foreach (Task _task in Tasks) { WEDMSetting wedmsetting = new WEDMSetting(); MGSetting mgsetting = new MGSetting(); switch (_task.TaskType) { case 1: _phaseID = 8; break; case 2: _phaseID = 9; break; case 3: wedmsetting = _wedmSettings.Where(s => s.ID == _task.ProgramID).FirstOrDefault() ?? new WEDMSetting(); //WEDMSettingRepository.QueryByTaskID(_task.TaskID); _phaseID = 10; break; case 4: _phaseID = 8; break; case 6: mgsetting = _mgSettings.Where(s => s.ID == _task.ProgramID).FirstOrDefault() ?? new MGSetting(); //MGSettingRepository.QueryByTaskID(_task.TaskID); _phaseID = 7; break; } _cad = _task.CADUser > 0 ? (_users.Where(u => u.UserID == _task.CADUser).FirstOrDefault() ?? new User()).FullName : ""; //UserRepository.GetUserByID(_task.CADUser).FullName : ""; _cam = _task.CAMUser > 0? (_users.Where(u => u.UserID == _task.CAMUser).FirstOrDefault() ?? new User()).FullName : ""; //UserRepository.GetUserByID(_task.CAMUser).FullName:""; _workshop = _task.WorkshopUser > 0? (_users.Where(u => u.UserID == _task.WorkshopUser).FirstOrDefault() ?? new User()).FullName : ""; //UserRepository.GetUserByID(_task.WorkshopUser).FullName:""; _qc = _task.QCUser > 0 ? (_users.Where(u => u.UserID == _task.QCUser).FirstOrDefault() ?? new User()).FullName : ""; //UserRepository.GetUserByID(_task.QCUser).FullName : ""; CNCMachInfo _machinfo = GetCNCMachinfo(_task, _cncmachInfos, _tasks, _edmDetails); //GetCNCMachinfo(_task,MachInfoRepository, TaskRepository, EDMDetailRepository); decimal TaskHour = 0; try { _phase = _pjPhases.Where(p => p.ProjectID == _task.ProjectID && p.PhaseID == _phaseID).FirstOrDefault() ?? new ProjectPhase();//ProjectPhaseRepository.GetProjectPhases(_task.ProjectID).Where(p => p.PhaseID == _phaseID).FirstOrDefault(); _planDate = _phase.PlanCFinish == new DateTime(1, 1, 1) ? _phase.PlanFinish.ToString("yyyy-MM-dd") : _phase.PlanCFinish.ToString("yyyy-MM-dd"); } catch { _planDate = "-"; } try { TaskHour = GetTotalHourByTaskID(_taskhours, _task.TaskID);//TaskHourRepository.GetTotalHourByTaskID(_task.TaskID); } catch { TaskHour = 0; } string _machineCode = GetMachineByTask(_taskhours, _machineInfos, _task.TaskID); //TaskHourRepository.GetMachineByTask(_task.TaskID) ?? ""; string Operater = GetOperaterByTaskID(_taskhours, _task.TaskID); //TaskHourRepository.GetOperaterByTaskID(_task.TaskID) ?? ""; SetupTaskStart _setupTask = new SetupTaskStart { TaskID = _task.TaskID, TaskName = _task.TaskName, State = Enum.GetName(typeof(TaskStatus), _task.State), MachinesCode = "", MachinesName = _machineCode, TotalTime = Convert.ToInt32(TaskHour), UserID = 0, UserName = Operater, }; //string _camDrawingPath = string.Empty; if (string.IsNullOrEmpty(CAMDrawingPath)) { if (_task.TaskType == 6) { CAMDrawingPath = SystemConfigRepo.GetTaskDrawingPath("CAD"); } else { CAMDrawingPath = SystemConfigRepo.GetTaskDrawingPath(); } } string taskType = string.Empty; int _mgtype = (_tasktypes.Where(t => t.ShortName == "MG" && t.Enable).FirstOrDefault() ?? new TaskType()).TaskID;//(TasktypeRepo.TaskTypes.Where(t => t.ShortName == "MG" && t.Enable).FirstOrDefault() ?? new TaskType()).TaskID;//6 if (_task.TaskType != _mgtype) { taskType = (_tasktypes.Where(t => t.TaskID == _task.TaskType && t.Enable).FirstOrDefault() ?? new TaskType()).Name;//TasktypeRepo.TaskTypes.Where(t => t.TaskID == _task.TaskType).Select(t => t.Name).FirstOrDefault(); } else { string _typeID = (_mgtype.ToString() + _task.OldID.ToString()); taskType = (_tasktypes.Where(t => t.TaskID == Convert.ToInt32(_typeID) && t.Enable).FirstOrDefault() ?? new TaskType()).Name;//TasktypeRepo.TaskTypes.ToList().Where(t => t.TaskID == Convert.ToInt32(_typeID)).Select(t => t.Name).FirstOrDefault(); } rows.Add(new TaskGridRowModel(_task, _cad, _cam, _workshop, _qc, CAMDrawingPath, _planDate, _setupTask, _machinfo, wedmsetting, mgsetting, taskType)); } }