private void Button_Click_3(object sender, RoutedEventArgs e) { foreach (var item in submitedQuestions.Items) { var d = item as QuestionOfSubmittedExam; rel_student_qusetion_exam query = (from g in context2.rel_student_qusetion_exam where g.StudentId == d.StudentId && g.ExamCode == d.ExamCode && g.QustCode == d.QustCode select g).FirstOrDefault(); query.DegreeMark = d.DegreeMark; context2.SaveChanges(); MessageBox.Show("Done"); } }
private void Button_Click(object sender, RoutedEventArgs e) { int QID = getQuestionsOfExam.ElementAt(i).QustCode; if ((i + 2) == QCounter) { next.Content = "Submit"; } double Degree = (from d in contect3.exam_qusetion where d.Question_Id == QID && d.Exam_Id == selectedExamId select d.Grade).FirstOrDefault(); //to submit the current answer of question if (CurrentQuestion == "text") { string Answer = studentTextAswer.Text; string ModelAnswer = (from m in contect3.textquestions where m.QustCode == QID select m.ModelAnswer).FirstOrDefault(); rel_student_qusetion_exam submitQues = new rel_student_qusetion_exam(); submitQues.QustCode = getQuestionsOfExam.ElementAt(i).QustCode; submitQues.ExamCode = selectedExamId; submitQues.StudentId = userID; submitQues.Answer = Answer; submitQues.ModelAnswer = ModelAnswer; if (ModelAnswer == Answer) { submitQues.DegreeMark = Degree; } else { submitQues.DegreeMark = 0; } contect3.rel_student_qusetion_exam.Add(submitQues); } else if (CurrentQuestion == "mcq") { bool right = false; List <string> Answer = new List <string>(); List <string> ModelAnswer = (from m in contect3.multichoices join v in contect3.msqmultivalues on m.MCQCode equals v.MCQCode where m.QustCode == QID select v.ModelAnswer).ToList(); if (A.IsChecked == true) { Answer.Add(A.Content.ToString()); } if (B.IsChecked == true) { Answer.Add(B.Content.ToString()); } if (C.IsChecked == true) { Answer.Add(C.Content.ToString()); } if (D.IsChecked == true) { Answer.Add(D.Content.ToString()); } if (ModelAnswer.Count == Answer.Count) { int j = 0; if (ModelAnswer.Contains(Answer.ElementAt(j))) { j++; right = true; } else { right = false; } } rel_student_qusetion_exam submitQues = new rel_student_qusetion_exam(); submitQues.QustCode = getQuestionsOfExam.ElementAt(i).QustCode; submitQues.ExamCode = selectedExamId; submitQues.StudentId = userID; foreach (var item in Answer) { submitQues.Answer += item + ","; } foreach (var item in ModelAnswer) { submitQues.ModelAnswer += item + ","; } if (right == true) { submitQues.DegreeMark = Degree; } if (right == false) { submitQues.DegreeMark = 0; } contect3.rel_student_qusetion_exam.Add(submitQues); } else if (CurrentQuestion == "tf") { string Answer; string ModelAnswer = (from m in contect3.qtruefalses where m.QustCode == QID select m.ModelAnswer).FirstOrDefault(); if (T.IsChecked == true) { Answer = "true"; } else { Answer = "false"; } rel_student_qusetion_exam submitQues = new rel_student_qusetion_exam(); submitQues.QustCode = getQuestionsOfExam.ElementAt(i).QustCode; submitQues.ExamCode = selectedExamId; submitQues.StudentId = userID; submitQues.Answer = Answer; submitQues.ModelAnswer = ModelAnswer; if (ModelAnswer == Answer) { submitQues.DegreeMark = Degree; } else { submitQues.DegreeMark = 0; } contect3.rel_student_qusetion_exam.Add(submitQues); } contect3.SaveChanges(); i++; if (i + 1 > QCounter) { CurrentQuestion = "theEnd"; Canvas.SetZIndex(ExamSubmit, ++z); getStuentExamListView(); } else { try { //to get the next question question questionIndex = getQuestionsOfExam.ElementAt(i); string QuestionContent = ""; if (questionIndex.type == "text") { var Question = (from qs in contect3.textquestions where qs.QustCode == questionIndex.QustCode select qs).FirstOrDefault(); QuestionContent = Question.question; CurrentQuestion = "text"; Canvas.SetZIndex(textAnswer, ++z); } if (questionIndex.type == "MSQ") { QuestionContent = (from qs in contect3.multichoices where qs.QustCode == questionIndex.QustCode select qs.question).FirstOrDefault(); List <string> choise = (from choisse in contect3.msqmultivalues where choisse.MCQCode == (from qs in contect3.multichoices where qs.QustCode == questionIndex.QustCode select qs.MCQCode).FirstOrDefault() select choisse.ModelAnswer).ToList(); A.Content = choise.ElementAt(0); B.Content = choise.ElementAt(1); C.Content = choise.ElementAt(2); D.Content = choise.ElementAt(3); CurrentQuestion = "mcq"; Canvas.SetZIndex(msqAnswer, ++z); } if (questionIndex.type == "true&false") { QuestionContent = (from qs in contect3.qtruefalses where qs.QustCode == questionIndex.QustCode select qs.question).FirstOrDefault(); CurrentQuestion = "tf"; Canvas.SetZIndex(tfAnswer, ++z); } question.Content = QuestionContent; } catch (Exception h) { } } }