/// <summary> /// Get quiz's questions. /// </summary> /// <returns>A List of DisplayQuestionModel.</returns> public async Task <List <DisplayQuestionModel> > GetQuestions() { QuestionData questionData = new QuestionData(_db); List <DisplayQuestionModel> questionModels = new List <DisplayQuestionModel>(); List <DataQuestionModel> dataQuestionModels = await questionData.GetQuestions(); foreach (var dataQuestionModel in dataQuestionModels) { DisplayQuestionModel newDisplayQuestionModel = new DisplayQuestionModel { DomainId = dataQuestionModel.DomainId, Id = dataQuestionModel.Id, Question = dataQuestionModel.Question, QuestionTypeId = dataQuestionModel.QuestionTypeId, }; if (!DisplayLinks.Any(x => x.QuestionId == dataQuestionModel.Id)) { // Les questions non ajoutées sont ajoutées dans la liste déroulante questionModels.Add(newDisplayQuestionModel); } else { // Les questions déjà liées sont affichées dans le tableau DisplayQuestions.Add(newDisplayQuestionModel); } } return(questionModels); }
/// <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"); }