示例#1
0
        public async Task <ValidationResult> UpdateAsync(int id, Quiz quiz, IEnumerable <QuizQuestion> questions)
        {
            if (id <= 0)
            {
                return(new ValidationResult(false, new ValidationError("The activity is invalid")));
            }

            quiz.SetId(id);

            if (!quiz.IsValid())
            {
                return(new ValidationResult(false, quiz.ValidationErrors));
            }

            if (!quiz.AddQuestions(questions))
            {
                return(new ValidationResult(false, quiz.ValidationErrors));
            }

            var quizWasUpdated = await _quizRepository.UpdateAsync(quiz);

            if (!quizWasUpdated)
            {
                return(new ValidationResult(false, new ValidationError("The activity wasn't found")));
            }

            return(new ValidationResult(true));
        }
示例#2
0
        public async Task <ValidationResult> CreateAsync(Quiz quiz, IEnumerable <QuizQuestion> questions)
        {
            if (!quiz.IsValid())
            {
                return(new ValidationResult(false, quiz.ValidationErrors));
            }

            if (!quiz.AddQuestions(questions))
            {
                return(new ValidationResult(false, quiz.ValidationErrors));
            }

            var createdQuizId = await _quizRepository.CreateAsync(quiz);

            if (createdQuizId <= 0)
            {
                return(new ValidationResult(false, new ValidationError("There was an error while creating the activity")));
            }

            return(new ValidationResult(true));
        }