private void CompleteTest() { _dispatcherTimer.Stop(); TestDefinition correctTd = new TestDefinition(); using (var db = new Testverktyg.Context.TestverktygContext()) { correctTd = db.TestDefinitions.Where(td => td.Id == _testForm.TestDefinitionId).Include(q => q.Questions.Select(a => a.Answers)).FirstOrDefault(); } _testForm.Score = StudentApp.Controllers.StudentController.CalculateScore(TestQuestions, correctTd.Questions); _testForm.IsCompleted = true; _testForm.FinishedDate = DateTime.Now; Repository <TestForm> .Instance.Update(_testForm); StudentPage s = new StudentPage(_studentAccount); s.Show(); this.Close(); }
public StudentPage(StudentAccount userAccount) { InitializeComponent(); WindowStartupLocation = WindowStartupLocation.CenterScreen; List <TestForm> testFormsList = new List <TestForm>(); List <TestForm> DonetestFormsList = new List <TestForm>(); List <TestForm> NotDonetestFormsList = new List <TestForm>(); using (var db = new Testverktyg.Context.TestverktygContext()) { testFormsList = db.TestForms.Where(x => x.StudentAccountId == userAccount.Id).Include(q => q.TestDefinition.Questions).ToList(); foreach (var item in testFormsList) { if (item.FinalDate < DateTime.Now) { Repository <TestForm> .Instance.Delete(item); } else { if (item.IsCompleted == true) { DonetestFormsList.Add(item); } else { NotDonetestFormsList.Add(item); } } } } UserAccount = userAccount; lvw_NotFinsihedTestForms.ItemsSource = NotDonetestFormsList; foreach (var item in DonetestFormsList) { DisplayedTests.Add(new DisplayedTest(item)); } lvw_FinishedTestForms.ItemsSource = DisplayedTests; }
public TestPage(TestForm testform, StudentAccount student) { InitializeComponent(); this.DataContext = this; using (var db = new Testverktyg.Context.TestverktygContext()) { td = (from d in db.TestDefinitions.Where(x => x.Id == testform.TestDefinitionId).Include(q => q.Questions.Select(a => a.Answers)) select d).FirstOrDefault(); } foreach (var item in td.Questions) { testquestions.Add(item); } foreach (var question in testquestions) { if (question.QuestionType == QuestionType.Open) { foreach (var answer in question.Answers) { answer.Text = ""; } } else { foreach (var answer in question.Answers) { answer.CheckedOrRanked = 0; } } } _testForm = testform; _studentAccount = student; DispatcherTimer dispatcherTimer = new DispatcherTimer(); dispatcherTimer.Tick += new EventHandler(dispatcherTimer_Tick); dispatcherTimer.Interval = new TimeSpan(0, 0, 1); _dispatcherTimer = dispatcherTimer; _dispatcherTimer.Start(); _testForm.StartDate = DateTime.Now; timer = _testForm.TimeLimit * 60; }
private void Button_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Är det säkert att du vill påbörja provet tiden börjar om du trycker Ja", "Starta Prov", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { //Starta provet var testForm = new TestForm(); using (var db = new Testverktyg.Context.TestverktygContext()) { if (lvw_NotFinsihedTestForms.SelectedItem != null) { var selectedTf = (TestForm)lvw_NotFinsihedTestForms.SelectedItem; testForm = db.TestForms.Where(x => x.Id == selectedTf.Id) .Include(a => a.TestDefinition.Questions.Select(b => b.Answers)) .FirstOrDefault(); } } TestPage t = new TestPage(testForm, UserAccount); t.Show(); this.Close(); } }