public void Create(DalQuiz entity) { Quiz test = new Quiz() { Title = entity.Title, CategoryId = entity.Category.Id }; test.Questions = entity.Questions.Select(question => new QuizQuestion() { Text = question.Text, AnswerOptions = question.AnswerOptions.Select(answer => new AnswerOption() { Text = answer, IsCorrect = answer == question.CorrectAnswer ? true : false }).ToList() }).ToList(); context.Set<Quiz>().Add(test); }
// Clear public void Update(DalQuiz entity) { Quiz test = context.Set<Quiz>().FirstOrDefault(t => t.Id == entity.Id); if (test != null) { test.Questions.Clear(); test.CategoryId = entity.Category.Id; test.Title = entity.Title; test.Questions = entity.Questions.Select(question => new QuizQuestion() { Text = question.Text, AnswerOptions = question.AnswerOptions.Select(answer => new AnswerOption() { Text = answer, IsCorrect = answer == question.CorrectAnswer ? true : false }).ToList(), }).ToList(); } }