Skip to content

Commit 133f777

Browse files
author
David Warwick
committed
Refactor survey answer handling logic
Refactored the logic for updating `SelectedOptionIds` by introducing a `for` loop to populate selected option IDs more robustly. Removed redundant code that updated `Survey.Questions` with the API response, simplifying the handling of survey answers. Retained data reload logic for non-branching surveys.
1 parent 24e63c0 commit 133f777

File tree

1 file changed

+1
-16
lines changed

1 file changed

+1
-16
lines changed

JwtIdentity.Client/Pages/Survey/Survey.razor.cs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ protected async Task HandleSelectAllThatApplyOption(SelectAllThatApplyAnswerView
467467
// Update the SelectedOptionIds string (comma-separated values)
468468
var selectedIds = new List<int>();
469469
var question = (SelectAllThatApplyQuestionViewModel)Survey.Questions.First(q => q.Id == answer.QuestionId);
470-
470+
471471
for (int i = 0; i < answer.SelectedOptions.Count && i < question.Options.Count; i++)
472472
{
473473
if (answer.SelectedOptions[i])
@@ -484,21 +484,6 @@ protected async Task HandleSelectAllThatApplyOption(SelectAllThatApplyAnswerView
484484
var response = await ApiService.PostAsync(ApiEndpoints.Answer, answer);
485485
if (response != null)
486486
{
487-
// Update the answer in the Survey.Questions
488-
foreach (var question in Survey.Questions)
489-
{
490-
if (question.Id == answer.QuestionId)
491-
{
492-
for (int i = 0; i < question.Answers.Count; i++)
493-
{
494-
if (question.Answers[i].Id == answer.Id)
495-
{
496-
question.Answers[i] = response;
497-
}
498-
}
499-
}
500-
}
501-
502487
// Only reload data for non-branching surveys
503488
// For branching surveys, we handle this in navigation
504489
if (!HasBranching)

0 commit comments

Comments
 (0)