public JsonResult AddNextStepInRunProcess(int idStep, int idnextstep, int idstepdiamond) { string IdUser = User.Identity.GetUserId(); HttpStatusCode status = HttpStatusCode.OK; string message; object response; Step stepchoosenext = stepService.findStep(idnextstep); Step idstepdk = stepService.findStep(idstepdiamond); StepRun runstep = stepService.findsteprun(idStep); stepService.changestatustep(runstep.Id, IdUser); ProcessRun processrun = processService.findProcessRun(runstep.idProcess); if (idstepdk != null) { stepService.addrunnextstep(processrun.Id, idstepdk); } //List<Step> liststep = stepService.findStepsOfProcess(processrun.IdProcess); List <TaskProcessRun> listruntask = taskService.findruntaskofstep(idStep); List <TaskProcessRun> listtaskclose = listruntask.Where(x => x.Status1.Name == "Finish").ToList(); //List<Step> nextstep = new List<Step>(); StepRun runnextstep = new StepRun(); //foreach (var item in liststep) //{ // if (runstep.NextStep1 == item.Key && item.StartStep == false) // { // nextstep.Add(item); // } //} if (stepchoosenext != null) { if (listtaskclose.Count == listruntask.Count) { runnextstep = stepService.addrunnextstep(processrun.Id, stepchoosenext); } } //foreach (var nexts in nextstep) //{ List <TaskProcess> listtasknextstep = taskService.findTaskOfStep(stepchoosenext.Id); taskService.addlistruntask(listtasknextstep, runnextstep); //} message = "Created ProcessRun Successfully"; response = new { message = message, status = status }; SetFlash(FlashType.success, "Next step success"); return(Json(response, JsonRequestBehavior.AllowGet)); }