/// <summary> /// 更新任务的人员 /// </summary> /// <param name="task">任务类</param> /// <param name="numbers">员工名字的字符串数组</param> public void UpdateByNumber(task task, string[] numbers) { int oldLen = task.task_employee.Count; int newLen = numbers.Length; int leastLength = oldLen < newLen ? oldLen : newLen; var employeeService = new EmployeeService(); var taskEmployeeService = new TaskEmployeeService(); for (int i = 0; i < leastLength; i++) { task_employee updateitem = taskEmployeeService.FindByTaskId(task.Id)[i]; updateitem.EmployeeId = employeeService.FindByNumber(numbers[i]).Id; taskEmployeeService.Update(updateitem); } for (int i = leastLength; i < oldLen; i++) { taskEmployeeService.Delete(taskEmployeeService.Find(task.task_employee.ElementAt(i).Id)); } for (int i = leastLength; i < newLen; i++) { taskEmployeeService.Insert(new task_employee { TaskId = task.Id, EmployeeId = employeeService.FindByNumber(numbers[i]).Id }); } }