public IActionResult AddQuestion(QuestionViewModel questionViewModel) { Exam exam = examRepository.Get(questionViewModel.ExamId); if (ModelState.IsValid) { Question qusetion = new Question { Text = questionViewModel.Text }; questionRepository.Add(qusetion); ExamQuestion examQuestion = new ExamQuestion { ExamId = questionViewModel.ExamId, QuestionId = qusetion.Id, Exam = exam, Question = qusetion }; for (int i = 0; i < 4; i++) { Choice choice = questionViewModel.Choices[i]; choiceRepository.Add(choice); QuestionChoice questionChoice = new QuestionChoice { Question = qusetion, Choice = choice, ChoiceId = choice.Id, QuestionId = qusetion.Id, }; questionChoiceRepository.Add(questionChoice); } examQuestionRepository.Add(examQuestion); return(RedirectToAction("Index", new { examId = questionViewModel.ExamId })); } return(View()); }
public int AddExamQuestion(DLModel.ExamQuestion examQuestion) { return(_examQuestionRepository.Add(examQuestion).ExamQuestionID); }