private bool ValidateQuestion(Form_question q, form_question_answer a) { if (q.question_type == Form_question_type.heading || q.question_type == Form_question_type.subheading) { return(true); } var valid = true; if (q.question_type == Form_question_type.shorttext) { valid = !string.IsNullOrEmpty(a.textValue); } else if (q.question_type == Form_question_type.date) { valid = a.dateValue != null; } else if (q.question_type == Form_question_type.singlechoice) { valid = a.intValue != null && a.intValue > 0; } else if (q.question_type == Form_question_type.multiplechoice) { valid = a.AnswerChoices != null && a.AnswerChoices.Any(ac => ac.selected); } a.Validation = new Validation { valid = valid, message = ValidationRequiredMessage }; return(valid); }
private form_question_answer ProcessAnswerChoices(form_question_answer qa) { qa.AnswerChoices = qa.Question.question_type == Form_question_type.multiplechoice ? qa.Question.ChoiceGroup?.GroupChoices.Select(x => new Form_submission_answer_choice { choice_id = x.choice_id, answer_id = qa.id, Choice = new Form_choice { name = x.Choice?.name }, selected = qa.AnswerChoices.FirstOrDefault(ac => ac.choice_id == x.choice_id) != null }).ToList() : null; return(qa); }