private static CaseEltInstance BuildStage(string id, tStage stage, string casePlanInstanceId) { var planItems = BuildPlanItems(stage, casePlanInstanceId); var result = new CaseEltInstance { Id = CaseEltInstance.BuildId(casePlanInstanceId, stage.id, 0), Name = stage.name, EltId = id, Type = CasePlanElementInstanceTypes.STAGE }; foreach (var planItem in planItems) { result.AddChild(planItem); } if (!result.ExitCriterions.Any() && stage.exitCriterion != null) { foreach (var exitCriteria in stage.exitCriterion) { var sEntry = stage.sentry.First(s => s.id == exitCriteria.sentryRef); result.AddExitCriteria(new Criteria(exitCriteria.name) { SEntry = BuildSEntry(sEntry) }); } } return(result); }