public async Task DownloadLesson(List <Lesson> ListLesson, string idLesson) { string nameLesson = null; //lưu tên Lesson để thông báo // Download Lesson foreach (var myLesson in ListLesson) { if (myLesson.Id.Equals(idLesson)) { nameLesson = myLesson.Name.Trim(); lessonDb = new LessonDatabaseAccess(); lessonDb.AddLesson(myLesson); break; } } RestQuestionService resQuestionService = new RestQuestionService(); List <Question> myLstQuestion = await resQuestionService.GetDataWithIDAsync(idLesson); // Lấy các câu hỏi có trong Lesson questionDb = new QuestionDatabaseAccess(); answerDb = new AnswerDatabaseAccess(); foreach (var myQuestion in myLstQuestion) { questionDb.AddQuestion(myQuestion); // Download Question RestAnswerService resAnswerService = new RestAnswerService(); List <Answer> myLstAnswer = await resAnswerService.GetDataWithIDAsync(myQuestion.QuestionID); // Lấy các câu trả lời có trong cầu hỏi foreach (var myAnswer in myLstAnswer) { answerDb.AddAnswer(myAnswer); //Download Answer } } DependencyService.Get <IMessage>().LongToast("Download " + nameLesson + " Completed"); }
//public List<Question> ListQuestion //{ // get // { // return _listQuestion; // } // set // { // _listQuestion = value; // OnPropertyChanged(); // } //} //public List<Answer> ListAnswer //{ // get // { // return _listAnswer; // } // set // { // _listAnswer = value; // OnPropertyChanged(); // } //} #endregion #region Methods private async Task GetDataQuestion(string idLesson) { //ListQuestion = new List<Question>(); lstQuestion = new List <Question>(); resQuestionService = new RestQuestionService(); Task <List <Question> > ahihi = resQuestionService.GetDataWithIDAsync(idLesson); //Task.WhenAll(ahihi); //ListQuestion = await ahihi; lstQuestion = await ahihi; // lstQuestion = ahihi.Result; } // Không dùng
} // Không dùng public async void GetData(StackLayout myLayout, string idLesson) { // Offline = true; // Lấy danh sách các câu hỏi. if (myOffline) // Đang Offline { //questionDb = new QuestionDatabaseAccess(); //lstQuestion = questionDb.GetQuestionDb(idLesson); lstQuestion = GetDataOffline.getQuetsionOffline(idLesson); } else // Đang Online { resQuestionService = new RestQuestionService(); Task <List <Question> > questionAsync = resQuestionService.GetDataWithIDAsync(idLesson); lstQuestion = await questionAsync; } foreach (var question in lstQuestion) { var myLableQuestion = new Label { Text = "" + question.Content, FontAttributes = FontAttributes.Bold }; myLayout.Children.Add(myLableQuestion); // Lay cac cau tra loi trong cau hoi if (myOffline) { //answerDb = new AnswerDatabaseAccess(); //lstAnswer = answerDb.GetAnswerDb(question.QuestionID); lstAnswer = GetDataOffline.getAnswerOffline(question.QuestionID); } else { resAnswerService = new RestAnswerService(); Task <List <Answer> > answerAsync = resAnswerService.GetDataWithIDAsync(question.QuestionID); lstAnswer = new List <Answer>(); lstAnswer = await answerAsync; } if (question.TypeQuestion == 1 || question.TypeQuestion == 3) // Trac Nghiem { foreach (var answer in lstAnswer) { lstAnswerLesson.Add(answer); Xamarin.Forms.Button myAnswer = new Xamarin.Forms.Button { Text = "" + answer.Content, Margin = 10 , // Command = CheckAnswerCommand(answer.AnswerID) Command = CheckAnswerCommand(answer) }; dicButton.Add(answer.AnswerID, myAnswer); // Danh sách lưu các button trắc nghiệm myLayout.Children.Add(myAnswer); } } else // Tu luan { foreach (var answer in lstAnswer) { lstAnswerLesson.Add(answer); var myEntryAnswer = new Entry { Placeholder = "" + answer.Content }; //dicTuLuan.Add(ans[k].IDAnswer, myEntryAnswer); dicTuLuan.Add(answer.AnswerID, myEntryAnswer); myLayout.Children.Add(myEntryAnswer); } } } Xamarin.Forms.Button myFinishButton = new Xamarin.Forms.Button { Text = "Finish" , Command = FinishCommand() }; myLayout.Children.Add(myFinishButton); }