private void CreateExamBtn_Click(object sender, RoutedEventArgs e) { if (ValidForm()) { Exam.ExamType = (ExamTypeModel)examTypesCombobox.SelectedItem; Exam.Date = (DateTime)examDate.SelectedDate; GlobalConfig.Connection.CreateExam(Exam); foreach (ExamGroupModel examGroup in Exam.ExamGroups) { examGroup.ExamId = Exam.Id; GlobalConfig.Connection.CreateExamGroup(examGroup); AnswerKeyModel answerKey = Evaluator.AnswerKeys.Find(a => a.Group.Name == examGroup.Group.Name); int counter = 0; foreach (QuestionModel question in examGroup.Questions) { question.ExamGroupId = examGroup.Id; GlobalConfig.Connection.CreateQuestion(question); foreach (var studentAnswers in Evaluator.StudentsAnswers) { if (studentAnswers.Group.Name == answerKey.Group.Name) { ResultModel r = new ResultModel { QuestionId = question.Id }; StudentModel model = GlobalConfig.Connection.GetStudent_ByRegNo(studentAnswers.Student.RegNo); r.Student = model; if (studentAnswers.AnswersList[counter].ToString() == answerKey.AnswersList.Substring(counter, 1)) { r.IsTrue = true; } else { r.IsTrue = false; } GlobalConfig.Connection.CreateResult(r); } } counter++; foreach (CourseOutcomeModel courseOutcome in question.QuestionOutcomes) { QuestionOutcomeModel model = new QuestionOutcomeModel(); model.CourseOutcomeId = courseOutcome.Id; model.QuestionId = question.Id; GlobalConfig.Connection.CreteQuestionOutcome(model); } } } CallingWindow.ExamComplete(Exam); this.Close(); } }
public List <AnswerKeyModel> GetAnswersKeys(string answerPath) { AnswersKeyPath = answerPath; answerKeys = File.ReadAllLines(AnswersKeyPath, Encoding.GetEncoding("iso-8859-9")); foreach (string answersString in answerKeys) { AnswerKeyModel a = new AnswerKeyModel(); a.Group.Name = answersString.Substring(0, 1); a.QuestionCount = answersString.Length - 1; a.AnswersList = answersString.Substring(1, a.QuestionCount); AnswerKeys.Add(a); } return(AnswerKeys); }