예제 #1
0
        public async Task AddQuestionToQuiz(int quizId, IQuestionDto question)
        {
            if (question == null)
            {
                throw new ArgumentNullException("question");
            }

            var quiz = await _context.Quizes.Include(x => x.Questions).FirstOrDefaultAsync(x => x.QuizId == quizId);
            if (quiz != null)
            {
                if (quiz.Questions == null)
                {
                    quiz.Questions = new List<QuestionDto>();
                }
                quiz.Questions.Add((QuestionDto)question);
                question.QuestionItems.Each(x => _context.QuestionItems.Add((QuestionItemDto)x));
                question.QuestionItems.Each(x => ((QuestionItemDto)x).Question = (QuestionDto)question);
                await _context.SaveChangesAsync();
            }
        }
예제 #2
0
 public IQuestionModel Map(IQuestionDto dto)
 {
     return Mapper.Map<Question>(dto);
 }