public static Question LoadQuestion(int id, string question_type) { Question question; if (question_type == "open") { question = new OpenQuestion(); } else { question = new CloseQuestion(); } connection.Open(); var command = new SQLiteCommand("select * from Question where ID = @id", connection); command.Parameters.AddWithValue("@id", id); var reader = command.ExecuteReader(); while (reader.Read()) { question.ID = reader.GetInt32(0); question.question = (string)reader.GetValue(1); question.answer = (string)reader.GetValue(2); } connection.Close(); return(question); }
/// <summary> /// Update- close question /// </summary> /// <param name="model"></param> public void Update(CloseQuestion model) { var question = this.context.CloseQuestions.Find(model.Id); question.Content = model.Content; question.Points = model.Points; question.HelpLink = model.HelpLink; this.context.SaveChanges(); }
public async Task <IActionResult> GeneralTestAsync(int index = 0) { var listQuestions = await repository.GetAllQuestions(); var listAnswers = await repository.GetAllAnswers(); var listSpelling = new List <Question>(listQuestions.Where(a => a.Category == "Орфография" && !a.IsOpen)); var listPunctuation = new List <Question>(listQuestions.Where(a => a.Category == "Пунктуация" && !a.IsOpen)); var listSyntax = new List <Question>(listQuestions.Where(a => a.Category == "Синтаксис" && !a.IsOpen)); var listMorphology = new List <Question>(listQuestions.Where(a => a.Category == "Морфология" && !a.IsOpen)); var listOpen = new List <Question>(listQuestions.Where(a => a.IsOpen)); Test test = new Test { CloseQuestions = new List <CloseQuestion>(), OpenQuestions = new List <OpenQuestion>() }; test.Name = $"Общий тест {index + 1}"; for (int i = 0; i < SPELLING_QUESTION_NUMBER; i++) { var cq = new CloseQuestion(listSpelling.ElementAt(index * SPELLING_QUESTION_NUMBER + i)); test.CloseQuestions.Add(cq); } for (int i = 0; i < PUNCT_QUESTION_NUMBER; i++) { var cq = new CloseQuestion(listPunctuation.ElementAt(index * PUNCT_QUESTION_NUMBER + i)); test.CloseQuestions.Add(cq); } test.CloseQuestions.Add(new CloseQuestion(listMorphology.ElementAt(index + 1))); test.CloseQuestions.Add(new CloseQuestion(listSyntax.ElementAt(index + 1))); foreach (var q in test.CloseQuestions) { q.Answers = new List <Answer>(listAnswers.Where(a => a.QuestionId == q.Id)); } for (int i = 0; i < OPEN_QUESTION_NUMBER; i++) { var cq = new OpenQuestion(listOpen.ElementAt(index * OPEN_QUESTION_NUMBER + i)); cq.RightAnswer = listAnswers.Where(a => a.QuestionId == cq.Id).ElementAt(0); test.OpenQuestions.Add(cq); } return(View(test)); }
public async Task <IActionResult> CategoryTestAsync(int index = 0, string category = "Орфография") { var listQuestions = await repository.GetQuestionsByCategoryOpen(category); Test test = new Test { CloseQuestions = new List <CloseQuestion>() }; test.Name = $"Тест по разделу '{category}' {index + 1}"; for (int i = 0; i < QUESTIONS_NUMBER; i++) { var cq = new CloseQuestion(listQuestions.ElementAt(index * QUESTIONS_NUMBER + i)); cq.Answers = await repository.GetUserAnswersByQuestionId(cq.Id); test.CloseQuestions.Add(cq); } return(View(test)); }
/// <summary> /// Add close question /// </summary> /// <param name="model"></param> /// <returns></returns> public int Add(CloseQuestion model) { this.context.CloseQuestions.Add(model); this.context.SaveChanges(); return(model.Id); }
public async Task <IActionResult> TestResultAsync(int testTry) { var userAnswers = await repository.GetUserTestTry(testTry); var listQuestions = await repository.GetAllQuestions(); var listAnswer = await repository.GetAllAnswers(); Test test = new Test { CloseQuestions = new List <CloseQuestion>(), OpenQuestions = new List <OpenQuestion>() }; foreach (var userAnswer in userAnswers) { var q = new Question(); q = listQuestions.Where(q => q.Id == userAnswer.QuestionId).ElementAt(0); if (q.IsOpen) { var oq = new OpenQuestion(q); oq.Choice = userAnswer.Answer; oq.RightAnswer = listAnswer.Where(a => a.QuestionId == q.Id).ElementAt(0); if (oq.Choice != null) { oq.Choice.ToLower(); } oq.RightAnswer.TextAnswer.ToLower(); test.OpenQuestions.Add(oq); } else { var cq = new CloseQuestion(q) { Answers = await repository.GetUserAnswersByQuestionId(userAnswer.QuestionId) }; var answerStr = userAnswer.Answer; foreach (var answer in cq.Answers) { if (answerStr.IndexOf($" {answer.Id} ") != -1) { answer.IsChecked = true; } } test.CloseQuestions.Add(cq); } } double right = 0; int wrong = 0; foreach (var question in test.CloseQuestions) { foreach (var answer in question.Answers) { if (answer.IsChecked == answer.IsRight) { right++; } else { wrong++; } } } foreach (var question in test.OpenQuestions) { if (question.Choice == question.RightAnswer.TextAnswer) { right++; } else { wrong++; } } test.Result = Math.Round(Convert.ToDouble(right / (right + wrong) * 100)); return(View(test)); }