public BaseAnswerModel GetQuestionByType(string baseQuestion) { var baseAnswerM = JsonConvert.DeserializeObject <BaseAnswerModel>(baseQuestion); if (Enum.TryParse(baseAnswerM.Type.ToString(), out type)) { switch (type) { case AnswerTypes.Textbox: { TextAnswerModel question = JsonConvert.DeserializeObject <TextAnswerModel>(baseQuestion); baseAnswerM = question as BaseAnswerModel; break; } case AnswerTypes.Textarea: { TextAreaAnswerModel question = JsonConvert.DeserializeObject <TextAreaAnswerModel>(baseQuestion); baseAnswerM = question as BaseAnswerModel; break; } case AnswerTypes.Radio: { RadioAnswerModel question = JsonConvert.DeserializeObject <RadioAnswerModel>(baseQuestion); baseAnswerM = question as BaseAnswerModel; break; } case AnswerTypes.Checkbox: { CheckBoxAnswerModel question = JsonConvert.DeserializeObject <CheckBoxAnswerModel>(baseQuestion); baseAnswerM = question as BaseAnswerModel; break; } case AnswerTypes.Dropdown: { DropdownAnswerModel question = JsonConvert.DeserializeObject <DropdownAnswerModel>(baseQuestion); baseAnswerM = question as BaseAnswerModel; break; } case AnswerTypes.GridRadio: { GridAnswerModel question = JsonConvert.DeserializeObject <GridAnswerModel>(baseQuestion); baseAnswerM = question as BaseAnswerModel; break; } } } return(baseAnswerM); }
private void SaveRadioAnswer(RadioAnswerModel data) { if (data.Answer.Length > 0) { var questionOptionId = _questionOptionService.Add(data.Id, Guid.Parse(data.Answer)); Answers answer = new Answers() { AnswerBoolean = true, AnswerDateTime = null, AnswerNumeric = null, AnswerText = null, RespondentId = respondentId, QuestionOptionId = questionOptionId }; var answerId = AddAsync(answer).Result; if (!String.IsNullOrEmpty(data.AdditionalAnswer)) { AddAdditionalChoice(data); } } }