예제 #1
0
        public async Task Put(int id, [FromBody] Model.Quiz quiz)
        {
            var existingQuiz = await _quizContext.Quizzes.FirstOrDefaultAsync(x => x.Id == id);

            _quizContext.Remove(existingQuiz);
            _quizContext.Add(quiz);
            await _quizContext.SaveChangesAsync();
        }
예제 #2
0
        public Quiz DeleteQuiz(int quizId)
        {
            var x = _context.Quizes.Include(q => q.Questions)
                    .ThenInclude(a => a.Answers)
                    .SingleOrDefault(i => i.Id == quizId);

            _context.Remove(x);
            _context.SaveChanges();
            return(x);
        }
        public Quiz DeleteQuiz(int quizId)
        {
            Quiz quiz = _quizContext
                        .Quizzes
                        .Include(x => x.Questions)
                        .First(q => q.Id == quizId);

            var questions = quiz.Questions;

            foreach (var q in questions)
            {
                _quizContext.Remove(q);
            }

            _quizContext.Remove(quiz);
            _quizContext.SaveChanges();

            return(quiz);
        }