public CreateQuestionViewModel()
 {
     Question = new Question();
     Questions = new ObservableCollection<Question>();
     _questionRepository = new QuestionRepository();
     Questions = _questionRepository.GetQuestions();
    
     Question.PropertyChanged += OnQuestion_PropertyChanged;
     Questions.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(Questions_CollectionChanged);
 }
 private void BtnUpdate_OnClick(object sender, RoutedEventArgs e)
 {
     var viewModel = this.DataContext as CreateQuestionViewModel;
     if (viewModel == null) return;
     {
         var question = new Question
         {
             Content = TxtContent.Text,
             OptionA = TxtOptionA.Text,
             OptionB = TxtOptionB.Text,
             OptionC = TxtOptionC.Text,
             OptionD = TxtOptionD.Text,
             Correct = _correct
         };
         viewModel.UpadteQuestionCommand.Execute(question);
         ResetControls();
     }
 }
        private void lvSelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var item = LvQuestions.SelectedItem;
            _question = item as Question;
            var viewModel = this.DataContext as CreateQuestionViewModel;
            if (viewModel == null) return;
            if (_question == null) return;

            viewModel.CloneQuestion = _question;

            TxtContent.Text = _question.Content;
            TxtOptionA.Text = _question.OptionA;
            TxtOptionB.Text = _question.OptionB;
            TxtOptionC.Text = _question.OptionC;
            TxtOptionD.Text = _question.OptionD;
            CoverterCorrectToRadioButton(_question.Correct);

            BtnAdd.IsEnabled = false;
            BtnRemove.IsEnabled = true;
            BtnUpdate.IsEnabled = true;
        }
 //AddQuestion
 public List<Question> AddQuestion(Question question)
 {
     if (question == null)
         throw new ArgumentNullException("question");
     if (!Questions.Contains(question))
     {
         Questions.Add(question);
     }
     return Questions;
 }
 //ContainsQuesion
 public bool ContantsQuestion(Question question)
 {
     if (question == null)
         throw new ArgumentNullException("question");
     return Questions.Contains(question);
 }
        //UpdateQuestion


        #endregion

        #region Private Helpers

        private List<Question> LoadQuestions()
        {
            Question question = null;
            List<Question> questions=new List<Question>();
            //using (Stream stream = GetResourceStream("./bin/Debug/Questions.xml"))

            XmlDocument doc = new XmlDocument();
            doc.Load("Questions.xml");
            XmlElement root = doc.DocumentElement;
            XmlNodeList rootQuestions = root.ChildNodes;
            for (int i = 0; i < rootQuestions.Count; i++)
            {
                question = new Question();

                XmlNode id = rootQuestions[i].SelectSingleNode("Id");
                XmlNode content = rootQuestions[i].SelectSingleNode("Content");
                XmlNode optionA = rootQuestions[i].SelectSingleNode("OptionA");
                XmlNode optionB = rootQuestions[i].SelectSingleNode("OptionB");
                XmlNode optionC = rootQuestions[i].SelectSingleNode("OptionC");
                XmlNode optionD = rootQuestions[i].SelectSingleNode("OptionD");
                XmlNode correct = rootQuestions[i].SelectSingleNode("Correct");

                if (id != null) question.Id = Int32.Parse(id.InnerText.ToString(CultureInfo.InvariantCulture));
                if (content != null) question.Content = content.InnerText.ToString(CultureInfo.InvariantCulture);
                if (optionA != null) question.OptionA = optionA.InnerText.ToString(CultureInfo.InvariantCulture);
                if (optionB != null) question.OptionB = optionB.InnerText.ToString(CultureInfo.InvariantCulture);
                if (optionC != null) question.OptionC = optionC.InnerText.ToString(CultureInfo.InvariantCulture);
                if (optionD != null) question.OptionD = optionD.InnerText.ToString(CultureInfo.InvariantCulture);
                if (correct != null) question.Correct = correct.InnerText.ToString(CultureInfo.InvariantCulture);
                
                questions.Add(question);
            }
            
            return questions;
        }