public JsonResult DeleteNextStepRun(int idStep) { HttpStatusCode status = HttpStatusCode.OK; string message; object response; StepRun runstep = stepService.findsteprun(idStep); List <StepRun> liststeprun = stepService.findStepsOfRunProcess(runstep.idProcess); StepRun stepback = new StepRun(); foreach (StepRun item in liststeprun) { if (item.Id != runstep.Id) { stepback = item; } } if (stepback.Figure == "Diamond") { StepRun stepbacknotdiamond = liststeprun.Where(x => x.NextStep1 == stepback.Key).OrderByDescending(x => x.Created_At).FirstOrDefault(); stepService.removeStepRun(stepback); stepService.deletenextsteprun(runstep, stepbacknotdiamond); } else { stepService.deletenextsteprun(runstep, stepback); } message = "Created ProcessRun Successfully"; response = new { message = message, status = status }; SetFlash(FlashType.success, "Delete Step"); return(Json(response, JsonRequestBehavior.AllowGet)); }