コード例 #1
0
        public static async Task <bool> UpdateQuizCascadingAsync(Quiz quiz)
        {
            bool updateQuizSucceeded = await UpdateQuiz(quiz).ConfigureAwait(true);

            if (!updateQuizSucceeded)
            {
                return(false);
            }
            foreach (var question in quiz.Questions)
            {
                //Updates question
                bool updateQuestionSucceeded = await QuestionRequest.UpdateQuestion(question).ConfigureAwait(true);

                if (!updateQuestionSucceeded)
                {
                    return(false);
                }
                // updateQuestion() also creates new answers for new questions
                if (question.QuestionId != 0)
                {
                    foreach (var answer in question.Answers)
                    {
                        //Updates answer
                        bool updateAnswerSucceeded = await AnswerRequest.UpdateAnswer(answer).ConfigureAwait(true);

                        if (!updateAnswerSucceeded)
                        {
                            return(false);
                        }
                    }
                }
            }

            return(true);
        }
コード例 #2
0
        //returns the quiz with all its questions and answers
        public static async Task <Quiz> GetCompleteQuizAsync(Quiz quiz)
        {
            var questionsTask = await QuestionRequest.GetQuestionListByQuizIdAsync(quiz.QuizId).ConfigureAwait(true);

            Question[] questions = questionsTask;
            foreach (Question question in questions)
            {
                var answersTask = await AnswerRequest.GetAnswerListByQuestionId(question.QuestionId).ConfigureAwait(true);

                Answer[] answers = answersTask;

                foreach (Answer answer in answers)
                {
                    question.Answers.Add(answer);
                }

                quiz.Questions.Add(question);
            }
            return(quiz);
        }