public static Question createByJToken(JToken data) { Question question = new Question() { Id = Convert.ToInt32(data["id"]), Text = data["text"].ToString(), CorectAnswerId = Convert.ToInt32(data["corectAnswerId"]) }; question.Answers = Answer.createByJToken(data["answers"], question); return question; }
//[ManyToOne(CascadeOperations = CascadeOperation.CascadeRead)] //public Question Question { get; set; } public static List<Answer> createByJToken(JToken data, Question question) { List<Answer> answers = new List<Answer>(); foreach (var answer in data) answers.Add(new Answer() { Id = Convert.ToInt32(answer["id"]), Text = answer["text"].ToString(), QuestionId = question.Id, // Question = question }); return answers; }
public Question getQuestion() { List<Answer> answers = new List<Answer>(); answers.Add(getCorrectAnswer()); answers.Add(new Answer() { Id = 2, Text = "a2" }); answers.Add(new Answer() { Id = 3, Text = "a3" }); foreach (Answer answer in answers) answer.QuestionId = 1; Question question = new Question() { Id = 1, Text = "Text", CorectAnswerId = 1, Answers = answers }; return question; }
public QuizeItemControl(Question _question, EventHandler _clickNext) { InitializeComponent(); LayoutRoot.DataContext = question = _question; clickNext = _clickNext; }