/// <summary> /// Get the question's answers. /// </summary> /// <param name="id">The question id.</param> /// <returns>The list of question's answers.</returns> private async Task <List <DisplayAnswerModel> > GetQuestionAnswers(string id) { // Database related helpers LinkQuestionAnswerData linkQuestionAnswerData = new LinkQuestionAnswerData(_db); AnswerData answerData = new AnswerData(_db); // Get question's answers List <DataLinkQuestionAnswerModel> dataLinkQuestionAnswerModels = await linkQuestionAnswerData.GetLinkedAnswers(id); // Build the display object answers List <DisplayAnswerModel> displayAnswerModels = new List <DisplayAnswerModel>(); foreach (var dataLinkQuestionAnswerModel in dataLinkQuestionAnswerModels) { DataAnswerModel dataAnswerModel = await answerData.GetAnswerById(dataLinkQuestionAnswerModel.AnswerId).ContinueWith((x) => { return(x.Result[0]); }); displayAnswerModels.Add(new DisplayAnswerModel { Answer = dataAnswerModel.Answer, Id = dataAnswerModel.Id, PlayerAnswer = dataAnswerModel.PlayerAnswer, Type = dataAnswerModel.Type, }); } return(displayAnswerModels); }
/// <summary> /// Get all the question's linked answers and display them. /// </summary> /// <param name="id">The question id.</param> public async void OnGetAsync(string id) { DisplayAnswers = new List <DisplayAnswerModel>(); // Getting the current question QuestionData questionData = new QuestionData(_db); var dataQuestionModels = await questionData.GetQuestionById(id); DisplayQuestionModel = new DisplayQuestionModel { DomainId = dataQuestionModels[0].DomainId, Id = dataQuestionModels[0].Id, Question = dataQuestionModels[0].Question, QuestionTypeId = dataQuestionModels[0].QuestionTypeId, }; // Getting Question type QuestionTypeData questionTypeData = new QuestionTypeData(_db); var dataQuestionTypeModels = await questionTypeData.GetQuestionTypeById(DisplayQuestionModel.QuestionTypeId); DisplayQuestionTypeModel = new DisplayQuestionTypeModel { Id = dataQuestionTypeModels[0].Id, QuestionType = dataQuestionTypeModels[0].QuestionType, }; // Getting links List <DisplayLinkQuestionAnswerModel> displayLinkQuestionAnswerModels = new List <DisplayLinkQuestionAnswerModel>(); LinkQuestionAnswerData linkQuestionAnswerData = new LinkQuestionAnswerData(_db); List <DataLinkQuestionAnswerModel> dataAccessLinkQuestionAnswerModels = await linkQuestionAnswerData.GetLinkedAnswers(id); foreach (DataLinkQuestionAnswerModel dataAccessLinkQuestionAnswerModel in dataAccessLinkQuestionAnswerModels) { displayLinkQuestionAnswerModels.Add(new DisplayLinkQuestionAnswerModel { AnswerId = dataAccessLinkQuestionAnswerModel.AnswerId, Id = dataAccessLinkQuestionAnswerModel.Id, QuestionId = dataAccessLinkQuestionAnswerModel.QuestionId, }); } DisplayLinks = displayLinkQuestionAnswerModels; // Getting answers for the dropdown list. List <DisplayAnswerModel> answers = await GetAnswers(); Answers = new SelectList( answers.Select(x => new { Id = x.Id, Answer = $"{x.Answer} ({(x.Type == true ? "Réponse correcte" : "Réponse incorrecte")})", }), "Id", "Answer"); }