Ejemplo n.º 1
0
        private void BtnSave_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                tests.Model.Sections sec = new tests.Model.Sections();
                sec.Name = tbSection.Text;
                db.Sections.Add(sec);
                db.SaveChanges();

                MainWindow.fr.Source = new Uri("/Pages/Sections.xaml", UriKind.RelativeOrAbsolute);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void btnSaveQ_Click(object sender, RoutedEventArgs e)
        {
            Questions q = new Questions();

            q.CreationDate    = DateTime.Now;
            q.QuestionContent = tbxQuestion.Text;
            tests.Model.Sections sec = (tests.Model.Sections)cbSections.SelectedItem;
            q.SectionId = sec.SectionId;
            db.Questions.Add(q);
            db.SaveChanges();


            foreach (WrapPanel item in wpListAnswer.Children)
            {
                Answers aw = new Answers();
                aw.QuestionId = q.QuestionId;
                foreach (object an in item.Children)
                {
                    if (an.GetType().Name == "TextBox")
                    {
                        TextBox tb = (TextBox)an;
                        aw.Content = tb.Text;
                    }
                    else if (an.GetType().Name == "CheckBox")
                    {
                        CheckBox cb = (CheckBox)an;
                        aw.IsCorrect = (bool)cb.IsChecked;
                    }
                }
                db.Answers.Add(aw);
                db.SaveChanges();
            }


            MainWindow.fr.Source = new Uri("/Pages/QuestionList.xaml", UriKind.RelativeOrAbsolute);
        }