Beispiel #1
0
        public async Task <IEnumerable <Question> > SaveQuestionsAsync(IEnumerable <QuestionModel> questions)
        {
            var newQuestions = questions.Select(q => new Question {
                Text    = q.Text,
                Points  = 10,
                QuizId  = q.QuizId,
                Answers = q.Answers.Select(a => new Answer {
                    Text = a.Text
                }).ToList()
            }).ToList(); // We do a final ToList so we get an actualy object in-memory, so that Ids update after save

            _db.AddRange(newQuestions);

            await _db.SaveChangesAsync();

            return(newQuestions);
        }