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(); } }
public IQuestionModel Map(IQuestionDto dto) { return Mapper.Map<Question>(dto); }