public string Get(string id) { var result = _context.Survey.FindAsync(id); if (result == null) { return("Not found"); } Survey survey = result.Result; JsonSurvey jsonSurvey = new JsonSurvey(); jsonSurvey.id = id; jsonSurvey.pwd = survey.PatternLock; List <JsonQuestion> jsonQuestionList = new List <JsonQuestion>(); Question[] questionList = _context.Question.Include(q => q.Survey).Where(m => m.RefSurveyID == id).ToArray(); foreach (Question question in questionList) { JsonQuestion jsonQuestion = new JsonQuestion(); jsonQuestionList.Add(jsonQuestion); jsonQuestion.question = question.QuestionDescription; switch (question.QuestionType) { case QuestionType.Input: jsonQuestion.type = "edit"; jsonQuestion.options = new string[0]; break; case QuestionType.Multiple: jsonQuestion.type = "multiple"; jsonQuestion.options = question.Options.Split(";"); break; case QuestionType.Single: jsonQuestion.type = "single"; jsonQuestion.options = question.Options.Split(";"); break; default: break; } } jsonSurvey.questions = jsonQuestionList.ToArray(); string jsonStr = ""; try { jsonStr = JsonSerializer.Serialize(jsonSurvey); } catch (Exception e) { return("Failed"); } return(jsonStr); }
private Question CreateQuestionModel(JsonQuestion jsonQuestion) { Question question = new Question() { QuestionStatement = jsonQuestion.Question, CorrectAnswer = jsonQuestion.CorrectAnswer, //IncorrectAnswers = incorrectAnswers, IncorrectAnswers = jsonQuestion.IncorrectAnswers.ToList(), Category1 = jsonQuestion.Category, Type = _typeRepository.GetTypeByName(jsonQuestion.Type), Difficulty = _difficultyRepository.GetDifficultyByName(jsonQuestion.Difficulty) }; return(question); }
public async Task <IHttpActionResult> getAllQuestion(int idArea, JsonQuestion model) { try { var _listQuestionQnAMaker = JsonConvert.DeserializeObject <List <QuestionQnAMaker> >(model.strQuestion); var _dataTable = ConvertToDataTable(_listQuestionQnAMaker); var _result = new List <GetAllQuestionByArea>(); _result = await _Services.GetAllQuestionByArea(idArea, _dataTable); CreateFileExcel(_result); byte[] _data_array = convertToByteFile(_template_path); var _base64String = Convert.ToBase64String(_data_array); return(Ok(_base64String)); } catch (Exception ex) { return(Ok(ex.Message.ToString())); } }