コード例 #1
0
 private void FuncToCall4(object context)
 {
     if (CreatedMainTopicTitle == null || CreatedSubTopicTitle == "")
     {
         MessageBox.Show("You must enter a name in order to create a main topic.");
     }
     else
     {
         using (SelfAssessmentDbContext db = new SelfAssessmentDbContext())
         {
             MainTopic checkMainTopic = db.MainTopics.Where(m => m.Title == CreatedMainTopicTitle).FirstOrDefault();
             if (checkMainTopic == null)
             {
                 db.MainTopics.Add(new MainTopic()
                 {
                     Title = CreatedMainTopicTitle
                 });
                 db.SaveChanges();
             }
             else
             {
                 MessageBox.Show("This main topic already exists!");
             }
         }
         MainTopics            = Context.MainTopics.ToList();
         CreatedMainTopicTitle = null;
     }
 }
コード例 #2
0
 private void FuncToCall3(object context)
 {
     if (SelectedSubTopic == null)
     {
         MessageBox.Show("You must select a sub-topic to delete");
     }
     else
     {
         using (SelfAssessmentDbContext newContext = new SelfAssessmentDbContext())
         {
             SubTopic retrievedSubTopic = newContext.SubTopics.Where(st => st.Id == SelectedSubTopic.Id).FirstOrDefault();
             newContext.SubTopics.Remove(retrievedSubTopic);
             newContext.SaveChanges();
         }
         SubTopics = Context.SubTopics.Include(m => m.MainTopic)
                     .Where(r => r.MainTopic.Id == SelectedMainTopic.Id)
                     .ToList();
         SelectedSubTopic       = null;
         TopicIntroduction      = null;
         TopicContent           = null;
         TopicSummary           = null;
         CreatedSubTopicTitle   = null;
         CreatedSubTopicIntro   = null;
         CreatedSubTopicContent = null;
         CreatedSubTopicSummary = null;
     }
 }
コード例 #3
0
 private void FuncToCall6(object context)
 {
     if (CreatedMainTopicTitle == null || CreatedSubTopicTitle == "")
     {
         MessageBox.Show("You must enter a valid name in order to delete a main topic.");
     }
     else
     {
         using (SelfAssessmentDbContext db = new SelfAssessmentDbContext())
         {
             List <SubTopic> subTopics = db.SubTopics
                                         .Include(s => s.MainTopic)
                                         .Where(m => m.MainTopic.Title == SelectedMainTopic.Title)
                                         .ToList();
             foreach (SubTopic subTopic in subTopics)
             {
                 db.SubTopics.Remove(subTopic);
             }
             MainTopic mainTopic = db.MainTopics.Where(m => m.Title == SelectedMainTopic.Title).FirstOrDefault();
             db.Set <MainTopic>().Remove(mainTopic);
             db.SaveChanges();
         }
         SelectedMainTopic     = null;
         MainTopics            = Context.MainTopics.ToList();
         CreatedMainTopicTitle = null;
         SubTopics             = null;
     }
 }
コード例 #4
0
        public void TearDown()
        {
            using (SelfAssessmentDbContext context = new SelfAssessmentDbContext())
            {
                List <TestResult> testTestResults = context.TestResults.ToList();
                foreach (var testResult in testTestResults)
                {
                    context.TestResults.Remove(testResult);
                }

                List <QuestionOption> testQuestionOptions = context.QuestionOptions.ToList();
                foreach (var questionOption in testQuestionOptions)
                {
                    context.QuestionOptions.Remove(questionOption);
                }

                List <Question> testQuestions = context.Questions.ToList();
                foreach (var question in testQuestions)
                {
                    context.Questions.Remove(question);
                }

                List <Test> testTests = context.Tests.ToList();
                foreach (var test in testTests)
                {
                    context.Tests.Remove(test);
                }

                List <TestSeries> testTestSeries = context.TestSeries.ToList();
                foreach (var testSeries in testTestSeries)
                {
                    context.TestSeries.Remove(testSeries);
                }

                List <SubTopic> testSubTopics = context.SubTopics.ToList();
                foreach (var subTopic in testSubTopics)
                {
                    context.SubTopics.Remove(subTopic);
                }

                List <MainTopic> testMainTopics = context.MainTopics.ToList();
                foreach (var mainTopic in testMainTopics)
                {
                    context.MainTopics.Remove(mainTopic);
                }

                List <Account> testAccounts = context.Accounts.Where(a => a.User.Username != "test1").ToList();
                foreach (var account in testAccounts)
                {
                    context.Accounts.Remove(account);
                }

                List <User> testUsers = context.Users.Where(a => a.Username != "test1").ToList();
                foreach (var user in testUsers)
                {
                    context.Users.Remove(user);
                }
                context.SaveChanges();
            }
        }
コード例 #5
0
 private void FuncToCall5(object context)
 {
     if (CreatedMainTopicTitle == null || CreatedSubTopicTitle == "")
     {
         MessageBox.Show("You must enter a valid name in order to update a main topic.");
     }
     else
     {
         using (SelfAssessmentDbContext db = new SelfAssessmentDbContext())
         {
             MainTopic mainTopic = db.MainTopics.Where(m => m.Title == SelectedMainTopic.Title).FirstOrDefault();
             mainTopic.Title = CreatedMainTopicTitle;
             db.Set <MainTopic>().Update(mainTopic);
             db.SaveChanges();
         }
         MainTopics            = Context.MainTopics.ToList();
         CreatedMainTopicTitle = null;
     }
 }
コード例 #6
0
        public void Setup()
        {
            User user = new User()
            {
                Username       = "******",
                PasswordHashed = "test2",
                Email          = "*****@*****.**",
                DateJoined     = DateTime.Now
            };

            Account account = new Account()
            {
                User = user,
            };

            TestSeries testSeries = new TestSeries()
            {
                TestSeriesName = "TestTestSeries",
            };

            Test test = new Test()
            {
                TestSeries = testSeries,
                TestName   = "TestName"
            };


            Test secondTest = new Test()
            {
                TestSeries = testSeries,
                TestName   = "TestName2"
            };

            TestResult testResult = new TestResult()
            {
                Account = account,
                Mark    = 30,
                Test    = test
            };

            MainTopic mainTopic = new MainTopic()
            {
                Title = "MainTopic"
            };

            SubTopic subTopic = new SubTopic()
            {
                MainTopic = mainTopic,
                Title     = "SubTopic"
            };

            using (SelfAssessmentDbContext context = new SelfAssessmentDbContext())
            {
                context.Accounts.Add(account);
                context.TestSeries.Add(testSeries);
                context.MainTopics.Add(mainTopic);
                context.SubTopics.Add(subTopic);
                context.Tests.Add(test);
                context.Tests.Add(secondTest);
                context.TestResults.Add(testResult);
                context.SaveChanges();
            }
        }