public IEnumerable<DalQuestion> GetAll() { List<Question> questions = context.Set<Question>().ToList(); List<DalQuestion> dalQuestions = new List<DalQuestion>(); foreach (var question in questions) { DalQuestion dalQuestion = new DalQuestion() { Id = question.Id, Text = question.Text, Options = new List<DalOption>() }; foreach (var option in question.Options) { DalOption dalOption = new DalOption() { Id = option.Id, IsAnswer = option.IsAnswer, QuestionId = option.QuestionId, Text = option.Text }; dalQuestion.Options.Add(dalOption); } dalQuestions.Add(dalQuestion); } return dalQuestions; }
public DalTest GetById(int key) { Test test = context.Set<Test>().FirstOrDefault(t => t.Id == key); DalTest dalTest = new DalTest() { Id = test.Id, Name = test.Name, Questions = new List<DalQuestion>() }; foreach (var question in test.Questions) { DalQuestion dalQuestion = new DalQuestion() { Id = question.Id, Text = question.Text, Options = new List<DalOption>() }; foreach (var option in question.Options) { DalOption dalOption = new DalOption() { Id = option.Id, IsAnswer = option.IsAnswer, QuestionId = option.QuestionId, Text = option.Text }; dalQuestion.Options.Add(dalOption); } dalTest.Questions.Add(dalQuestion); } return dalTest; }