Skip to content

Instantly share code, notes, and snippets.

@hughesjs
Created April 8, 2020 03:31
Show Gist options
  • Save hughesjs/9c2a39acdc93f81220d04d97b36224a1 to your computer and use it in GitHub Desktop.
Save hughesjs/9c2a39acdc93f81220d04d97b36224a1 to your computer and use it in GitHub Desktop.
private void SaveResults()
{
List<AnswerData> answers = new List<AnswerData>();
foreach (GroupBox group in questionGroups)
{
JObject question = (JObject) group.Tag;
Enum.TryParse((string)question["questiontype"], out QuestionType qType);
AnswerData answer;
switch (qType)
{
case QuestionType.YesNo:
case QuestionType.MultipleChoiceExclusive:
answer = new AnswerData(question, group.Controls
.OfType<TableLayoutPanel>()
.First().Controls
.Cast<RadioButton>()
.Where(c=>c.Checked)
.Select(c=>c.Text)
.ToArray());
break;
case QuestionType.MultipleChoiceNotExclusive:
answer = new AnswerData(question, group.Controls
.OfType<TableLayoutPanel>()
.First()
.Controls.OfType<CheckBox>()
.Where(c => c.Checked)
.Select(c => c.Text)
.ToArray());
break;
case QuestionType.FreeComment:
answer = new AnswerData(question, group.Controls
.OfType<TableLayoutPanel>()
.First()
.Controls.OfType<RichTextBox>()
.Select(c=>c.Rtf)
.ToArray());
break;
default:
throw new ArgumentOutOfRangeException();
}
answers.Add(answer);
}
Task.Run(() => _client.Save(answers, _metadata, _client, _site, _fsr, _customer));
Close();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment