public IActionResult CreateExam(ExamCreateModel model) { Exam exam = new Exam(); int d = Convert.ToInt32(model.Title); exam.ExamContent = model.Content; exam.ExamTitle = titles[d - 1].ToString(); exam.CreatedDate = DateTime.Now; _examService.Add(exam); int exam_id = exam.ExamId; for (int i = 0; i < 4; i++) { Question question = new Question(); question.ExamId = exam_id; question.QuestionContent = model.Questions[i].QuestionContent; _questionService.Add(question); question.ExamId = exam_id; int question_id = question.QuestionId; for (int j = 0; j < 4; j++) { Option option = new Option(); option.selection = model.Questions[i].Options[j].selection; option.QuestionId = question_id; string a = model.Questions[i].Answer.ToString().ToLower(); if (((model.Questions[i].Answer) - 65) == j) { option.IsCorrect = "true"; } else { option.IsCorrect = "false"; } _optionsService.Add(option); } } return(View("Index")); }