コード例 #1
0
        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");
        }