public IHttpActionResult EditMultipleProjects(PostEditProjects postEditProjects) { if (postEditProjects.EditProjects.Count > 0) { using (TransactionScope tranScope = new TransactionScope()) { var projectId = postEditProjects.ProjectId; var parentCode = postEditProjects.EditProjects[0].ParentCode; var projects = ProjectInfo.Search(pi => pi.ProjectId == projectId).ToList(); var usCode = projects[0].USCode; var store = StoreBasicInfo.GetStorInfo(usCode); var minExecuteSequence = postEditProjects.EditProjects.Min(p => p.ExecuteSequence); var maxExecuteSequance = postEditProjects.EditProjects.Max(p => p.ExecuteSequence); foreach (TopNavigator nav in postEditProjects.EditProjects) { var workflow = BaseWFEntity.GetWorkflowEntity(postEditProjects.ProjectId, nav.Code); workflow.Edit(); } string[] cancelWorkflowCodes = FlowInfo.Search(f => f.ParentCode == parentCode && f.ExecuteSequence <= maxExecuteSequance + 1).Select(f => f.Code).ToArray(); TaskWork.Cancel(t => cancelWorkflowCodes.Contains(t.TypeCode) && t.RefID == postEditProjects.ProjectId && t.Status != TaskWorkStatus.Finished); postEditProjects.EditProjects.Where(n => n.ExecuteSequence == minExecuteSequence).ToList().ForEach(n => { var project = projects.FirstOrDefault(pi => pi.FlowCode == n.Code); var originator = Employee.GetSimpleEmployeeByCode(project.CreateUserAccount); var source = FlowInfo.Get(n.ParentCode); var taskType = FlowInfo.Get(n.Code); TaskWork task = new TaskWork(); task.Id = Guid.NewGuid(); task.SourceCode = source.Code; task.SourceNameENUS = source.NameENUS; task.SourceNameZHCN = source.NameZHCN; task.Status = TaskWorkStatus.UnFinish; task.StatusNameZHCN = "任务"; task.StatusNameENUS = "任务"; task.Title = TaskWork.BuildTitle(postEditProjects.ProjectId, store.NameZHCN, store.NameENUS); task.RefID = postEditProjects.ProjectId; task.StoreCode = usCode; task.ReceiverAccount = originator.Code; task.ReceiverNameENUS = originator.NameENUS; task.ReceiverNameZHCN = originator.NameZHCN; task.TypeCode = taskType.Code; task.TypeNameENUS = taskType.NameENUS; task.TypeNameZHCN = taskType.NameZHCN; task.Url = TaskWork.BuildUrl(n.Code, projectId, ""); task.CreateTime = DateTime.Now; task.CreateUserAccount = ClientCookie.UserCode; task.Sequence = 0; task.ActivityName = "Start"; task.Add(); }); tranScope.Complete(); } return(Ok()); } else { return(BadRequest("you must select projects to be edited!")); } }