private Quiz MapQuiz(QuizViewModel.Quiz data) { var quiz = new Quiz(); quiz.QuizName = data.QuizName; //quiz.TeacherName = User.Identity.Name; foreach (var questionData in data.Questions) { var question = new Question(); question.Text = questionData.Text; question.CorrectAnswer = new Answer() { Text = questionData.CorrectAnswer }; foreach (var incorrectData in questionData.IncorrectAnswers) { question.Answers.Add(new Answer() { Text = incorrectData }); } quiz.Questions.Add(question); } return(quiz); }
public ActionResult Create(QuizViewModel.Quiz data) { var quiz = this.MapQuiz(data); db.Quizzes.Add(quiz); db.SaveChanges(); return(null); }
private QuizViewModel.Quiz MapQuiz(Quiz data) { var quiz = new QuizViewModel.Quiz(); quiz.QuizName = data.QuizName; quiz.QuizID = data.QuizID; foreach (var questionData in data.Questions) { var question = new QuizViewModel.Question(); question.Text = questionData.Text; question.CorrectAnswer = questionData.CorrectAnswer.Text; foreach (var incorrectData in questionData.Answers) { question.IncorrectAnswers.Add(incorrectData.Text); } quiz.Questions.Add(question); } return(quiz); }