@@ -156,6 +156,19 @@ public async Task GenerateDemoSurveyResponsesAsync(Survey survey, int numberOfUs
156156 return ( false , "Survey not found" ) ;
157157 }
158158
159+ _logger . LogInformation ( "Loaded survey {SurveyId} with {QuestionCount} questions and {GroupCount} groups" ,
160+ surveyId , survey . Questions ? . Count ?? 0 , survey . QuestionGroups ? . Count ?? 0 ) ;
161+
162+ // Log question types for debugging
163+ if ( survey . Questions != null )
164+ {
165+ foreach ( var q in survey . Questions )
166+ {
167+ _logger . LogDebug ( "Question {QuestionId}: Type={Type}, GroupId={GroupId}" ,
168+ q . Id , q . GetType ( ) . Name , q . GroupId ) ;
169+ }
170+ }
171+
159172 // If there are no question groups, the survey is valid (backward compatibility)
160173 if ( survey . QuestionGroups == null || ! survey . QuestionGroups . Any ( ) )
161174 {
@@ -167,6 +180,9 @@ public async Task GenerateDemoSurveyResponsesAsync(Survey survey, int numberOfUs
167180 var mcQuestions = survey . Questions . OfType < MultipleChoiceQuestion > ( ) . ToList ( ) ;
168181 var satQuestions = survey . Questions . OfType < SelectAllThatApplyQuestion > ( ) . ToList ( ) ;
169182
183+ _logger . LogInformation ( "Found {MCCount} MultipleChoice and {SATCount} SelectAllThatApply questions" ,
184+ mcQuestions . Count , satQuestions . Count ) ;
185+
170186 var mcIds = mcQuestions . Select ( q => q . Id ) . ToList ( ) ;
171187 var satIds = satQuestions . Select ( q => q . Id ) . ToList ( ) ;
172188
@@ -179,6 +195,15 @@ public async Task GenerateDemoSurveyResponsesAsync(Survey survey, int numberOfUs
179195 ( co . MultipleChoiceQuestionId . HasValue && mcIds . Contains ( co . MultipleChoiceQuestionId . Value ) ) ||
180196 ( co . SelectAllThatApplyQuestionId . HasValue && satIds . Contains ( co . SelectAllThatApplyQuestionId . Value ) ) )
181197 . ToListAsync ( ) ;
198+
199+ _logger . LogInformation ( "Loaded {OptionCount} choice options" , allOptions . Count ) ;
200+
201+ foreach ( var opt in allOptions )
202+ {
203+ _logger . LogDebug ( "Option {OptionId}: '{Text}', BranchToGroupId={BranchTo}, MC={MC}, SAT={SAT}" ,
204+ opt . Id , opt . OptionText , opt . BranchToGroupId ,
205+ opt . MultipleChoiceQuestionId , opt . SelectAllThatApplyQuestionId ) ;
206+ }
182207 }
183208
184209 // Assign loaded options back to questions
@@ -219,11 +244,16 @@ public async Task GenerateDemoSurveyResponsesAsync(Survey survey, int numberOfUs
219244 var currentGroupNumber = groupNumbersToCheck . Dequeue ( ) ;
220245 var currentGroup = survey . QuestionGroups . FirstOrDefault ( g => g . GroupNumber == currentGroupNumber ) ;
221246
222- if ( currentGroup == null )
247+ // Group 0 might not exist in QuestionGroups table (it's implicit/default)
248+ // Still process questions in group 0 even if no QuestionGroup record exists
249+ if ( currentGroup == null && currentGroupNumber != 0 )
250+ {
251+ _logger . LogWarning ( "Group {GroupNumber} not found in QuestionGroups table" , currentGroupNumber ) ;
223252 continue ;
253+ }
224254
225- // Check NextGroupId (if it stores GroupNumber )
226- if ( currentGroup . NextGroupId . HasValue && ! reachableGroupNumbers . Contains ( currentGroup . NextGroupId . Value ) )
255+ // Check NextGroupId (only if group record exists )
256+ if ( currentGroup != null && currentGroup . NextGroupId . HasValue && ! reachableGroupNumbers . Contains ( currentGroup . NextGroupId . Value ) )
227257 {
228258 reachableGroupNumbers . Add ( currentGroup . NextGroupId . Value ) ;
229259 groupNumbersToCheck . Enqueue ( currentGroup . NextGroupId . Value ) ;
0 commit comments