@@ -194,7 +194,7 @@ public async Task GenerateDemoSurveyResponsesAsync(Survey survey, int numberOfUs
194194
195195 // Check for empty groups
196196 var emptyGroups = survey . QuestionGroups
197- . Where ( g => ! survey . Questions . Any ( q => q . GroupId == g . Id ) )
197+ . Where ( g => ! survey . Questions . Any ( q => q . GroupId == g . GroupNumber ) )
198198 . ToList ( ) ;
199199
200200 if ( emptyGroups . Any ( ) )
@@ -206,62 +206,58 @@ public async Task GenerateDemoSurveyResponsesAsync(Survey survey, int numberOfUs
206206 }
207207
208208 // Find all reachable groups starting from group 0
209- var reachableGroups = new HashSet < int > ( ) ;
210- var groupsToCheck = new Queue < int > ( ) ;
209+ var reachableGroupNumbers = new HashSet < int > ( ) ;
210+ var groupNumbersToCheck = new Queue < int > ( ) ;
211211
212212 // Start with group 0 (default group) - it's always the entry point
213- var defaultGroup = survey . QuestionGroups . FirstOrDefault ( g => g . GroupNumber == 0 ) ;
214- if ( defaultGroup != null )
215- {
216- reachableGroups . Add ( defaultGroup . Id ) ;
217- groupsToCheck . Enqueue ( defaultGroup . Id ) ;
218- }
213+ reachableGroupNumbers . Add ( 0 ) ;
214+ groupNumbersToCheck . Enqueue ( 0 ) ;
219215
220216 // Traverse all possible paths
221- while ( groupsToCheck . Count > 0 )
217+ while ( groupNumbersToCheck . Count > 0 )
222218 {
223- var currentGroupId = groupsToCheck . Dequeue ( ) ;
224- var currentGroup = survey . QuestionGroups . FirstOrDefault ( g => g . Id == currentGroupId ) ;
219+ var currentGroupNumber = groupNumbersToCheck . Dequeue ( ) ;
220+ var currentGroup = survey . QuestionGroups . FirstOrDefault ( g => g . GroupNumber == currentGroupNumber ) ;
225221
226222 if ( currentGroup == null )
227223 continue ;
228224
229- // Check NextGroupId
230- if ( currentGroup . NextGroupId . HasValue && ! reachableGroups . Contains ( currentGroup . NextGroupId . Value ) )
225+ // Check NextGroupId (if it stores GroupNumber)
226+ if ( currentGroup . NextGroupId . HasValue && ! reachableGroupNumbers . Contains ( currentGroup . NextGroupId . Value ) )
231227 {
232- reachableGroups . Add ( currentGroup . NextGroupId . Value ) ;
233- groupsToCheck . Enqueue ( currentGroup . NextGroupId . Value ) ;
228+ reachableGroupNumbers . Add ( currentGroup . NextGroupId . Value ) ;
229+ groupNumbersToCheck . Enqueue ( currentGroup . NextGroupId . Value ) ;
234230 }
235231
236232 // Check branching from questions in this group
237- var questionsInGroup = survey . Questions . Where ( q => q . GroupId == currentGroupId ) . ToList ( ) ;
233+ var questionsInGroup = survey . Questions . Where ( q => q . GroupId == currentGroupNumber ) . ToList ( ) ;
238234
239235 foreach ( var question in questionsInGroup )
240236 {
241237 // Check True/False branching
242238 if ( question is TrueFalseQuestion tfQuestion )
243239 {
244- if ( tfQuestion . BranchToGroupIdOnTrue . HasValue && ! reachableGroups . Contains ( tfQuestion . BranchToGroupIdOnTrue . Value ) )
240+ if ( tfQuestion . BranchToGroupIdOnTrue . HasValue && ! reachableGroupNumbers . Contains ( tfQuestion . BranchToGroupIdOnTrue . Value ) )
245241 {
246- reachableGroups . Add ( tfQuestion . BranchToGroupIdOnTrue . Value ) ;
247- groupsToCheck . Enqueue ( tfQuestion . BranchToGroupIdOnTrue . Value ) ;
242+ reachableGroupNumbers . Add ( tfQuestion . BranchToGroupIdOnTrue . Value ) ;
243+ groupNumbersToCheck . Enqueue ( tfQuestion . BranchToGroupIdOnTrue . Value ) ;
248244 }
249245
250- if ( tfQuestion . BranchToGroupIdOnFalse . HasValue && ! reachableGroups . Contains ( tfQuestion . BranchToGroupIdOnFalse . Value ) )
246+ if ( tfQuestion . BranchToGroupIdOnFalse . HasValue && ! reachableGroupNumbers . Contains ( tfQuestion . BranchToGroupIdOnFalse . Value ) )
251247 {
252- reachableGroups . Add ( tfQuestion . BranchToGroupIdOnFalse . Value ) ;
253- groupsToCheck . Enqueue ( tfQuestion . BranchToGroupIdOnFalse . Value ) ;
248+ reachableGroupNumbers . Add ( tfQuestion . BranchToGroupIdOnFalse . Value ) ;
249+ groupNumbersToCheck . Enqueue ( tfQuestion . BranchToGroupIdOnFalse . Value ) ;
254250 }
255251 }
256252 // Check Multiple Choice branching
257253 else if ( question is MultipleChoiceQuestion mcQuestion && mcQuestion . Options != null )
258254 {
259255 foreach ( var option in mcQuestion . Options )
260256 {
261- if ( option . BranchToGroupId . HasValue && ! reachableGroups . Contains ( option . BranchToGroupId . Value ) )
257+ if ( option . BranchToGroupId . HasValue && ! reachableGroupNumbers . Contains ( option . BranchToGroupId . Value ) )
262258 {
263- reachableGroups . Add ( option . BranchToGroupId . Value ) ;
264- groupsToCheck . Enqueue ( option . BranchToGroupId . Value ) ;
259+ reachableGroupNumbers . Add ( option . BranchToGroupId . Value ) ;
260+ groupNumbersToCheck . Enqueue ( option . BranchToGroupId . Value ) ;
265261 }
266262 }
267263 }
@@ -270,10 +266,10 @@ public async Task GenerateDemoSurveyResponsesAsync(Survey survey, int numberOfUs
270266 {
271267 foreach ( var option in satQuestion . Options )
272268 {
273- if ( option . BranchToGroupId . HasValue && ! reachableGroups . Contains ( option . BranchToGroupId . Value ) )
269+ if ( option . BranchToGroupId . HasValue && ! reachableGroupNumbers . Contains ( option . BranchToGroupId . Value ) )
274270 {
275- reachableGroups . Add ( option . BranchToGroupId . Value ) ;
276- groupsToCheck . Enqueue ( option . BranchToGroupId . Value ) ;
271+ reachableGroupNumbers . Add ( option . BranchToGroupId . Value ) ;
272+ groupNumbersToCheck . Enqueue ( option . BranchToGroupId . Value ) ;
277273 }
278274 }
279275 }
@@ -282,7 +278,7 @@ public async Task GenerateDemoSurveyResponsesAsync(Survey survey, int numberOfUs
282278
283279 // Find orphaned groups (groups that are not reachable)
284280 var orphanedGroups = survey . QuestionGroups
285- . Where ( g => g . GroupNumber != 0 && ! reachableGroups . Contains ( g . Id ) )
281+ . Where ( g => g . GroupNumber != 0 && ! reachableGroupNumbers . Contains ( g . GroupNumber ) )
286282 . ToList ( ) ;
287283
288284 if ( orphanedGroups . Any ( ) )
0 commit comments