コード例 #1
0
        public IActionResult ExamDelete(int id)
        {
            if (id != 0)
            {
                Exam deletedExam = _examService.GetById(id);
                _examService.Delete(deletedExam);

                List <Question> questions = new List <Question>();
                questions = _questionService.GetAll().Where(x => x.ExamId == id).ToList();

                foreach (var q in questions)
                {
                    _questionService.Delete(q);

                    List <Option> options = new List <Option>();
                    options = _optionsService.GetAll().Where(x => x.QuestionId == q.QuestionId).ToList();

                    foreach (var o in options)
                    {
                        _optionsService.Delete(o);
                    }
                }
            }
            return(RedirectToAction("ExamList"));
        }