protected override async Task OnInitializedAsync() { var(res2, answer, _) = await ExamServices.GetAnswer("", ExamId, QuestionNum); Console.WriteLine(res2); if (res2 == ErrorCodes.Success) { _answer = answer; if (answer is ChoiceAnswer choiceAnswer && Question is ChoiceQuestion choiceQuestion) { if (choiceQuestion.MultiChoice) { _choiceChecked = new bool[choiceQuestion.Choices.Count]; foreach (var i in choiceAnswer.Choices) { _choiceChecked[i] = true; } } else { _choiceSingle = choiceAnswer.Choices[0]; } } else if (answer is ShortAnswer shortAnswer && Question is ShortAnswerQuestion shortAnswerQuestion) { _answerString = shortAnswer.Answer; }
private IActionResult UpdateRender(string partName, string actionName, long id) { if (id <= 0) { return(BadRequest()); } // Lấy mục câu hỏi var testCategory = _TestCategoryManager.Get(id); if (testCategory == null) { return(NotFound()); } // Lấy danh sách câu trả lời var listeningBaseQuestions = _ListeningBaseQuestionManager.GetAll(testCategory.Id).ToList(); // Tạo câu hỏi nếu chưa có if (listeningBaseQuestions.Count <= 0) { listeningBaseQuestions = ListeningBaseQuestion.Generate(testCategory.PartId == 1 ? Config.MAX_LISTENING_PART_1_QUESTION : Config.MAX_LISTENING_PART_2_QUESTION, 3); } // Chuyển json câu hỏi thành danh sách để thao tác for (int i = 0; i < listeningBaseQuestions.Count(); i++) { if (listeningBaseQuestions[i].Answers != null && listeningBaseQuestions[i].Answers.Length > 0) { listeningBaseQuestions[i].AnswerList = JsonConvert.DeserializeObject <List <BaseAnswer> >(listeningBaseQuestions[i].Answers); } else { listeningBaseQuestions[i].AnswerList = BaseAnswer.Generate(3); } } // Lấy danh sách MEDIA var listeningMedia = _ListeningMediaManager.GetByCategory(testCategory.Id); return(View($"{partName}/{actionName}", new ListeningBaseCombined { TestCategory = testCategory, ListeningBaseQuestions = listeningBaseQuestions, ListeningMedia = listeningMedia })); }
protected override async Task OnInitializedAsync() { var(res, answer, time) = await ExamServices.GetAnswer(UserId, ExamId, QuestionNum); if (res == ErrorCodes.Success) { _answer = answer; _time = time; } else if (res == ErrorCodes.QuestionNotAnswered) { _displayText = "The exam taker did not answered this question"; } else { _displayText = "Error fetching answer: " + ErrorCodes.MessageMap[res]; } }
override public void Assign(BaseAnswer answer) { base.Assign(answer); ValueAnswer = ((TextAnswer)answer).ValueAnswer; }