/// <summary> /// update question answer /// </summary> /// <param name="obj"></param> /// <returns></returns> public int updateAnswerQuizeQuestion(question_answer obj) { var data = context.question_answer.Where(q => q.userId == obj.userId && q.questionId == obj.questionId).FirstOrDefault(); data.answer = obj.answer; //context.question_answer.Add(obj); context.SaveChanges(); return(obj.Id); }
void ReadCompleteLines(string fullTxt) { string[] txtLines = fullTxt.Split('\n'); for (int i = 0; i < txtLines.Length; i += 2) { question_answer p_r = new question_answer(); p_r.answer = txtLines[i].Trim(); p_r.question = txtLines[i + 1].Trim(); list_question_answer.Add(p_r); } }
public void SendExamResult(int examid, int studentid, string answers) { Exam thisExam = new Exam(); Users thisStudent = new Users(); thisExam = Database.Session.Load <Exam>(examid); thisStudent = Database.Session.Load <Users>(studentid); string _students_answers = ""; string _correct_answers = ""; var examDetailsArray = JsonConvert.DeserializeObject <List <GetFormData> >(answers); int totalResult = 0, point_per_question = (100 / thisExam.ExamQuestions.Count); question_answer[] questionsAndAnswers = new question_answer[examDetailsArray.Count]; for (int i = 0; i < examDetailsArray.Count; i++) { questionsAndAnswers[i].answer = examDetailsArray[i].Name.ToString()[examDetailsArray[i].Name.Length - 1]; questionsAndAnswers[i].question_number = examDetailsArray[i].Name.ToString().TrimEnd('A', 'B', 'C', 'D', 'E'); } foreach (var answer in questionsAndAnswers) { var getQuestionFromDatabase = Database.Session.Load <Questions>(Convert.ToInt32(answer.question_number)); _students_answers += answer.answer + ","; _correct_answers += getQuestionFromDatabase.TrueAnswer + ","; if (getQuestionFromDatabase.TrueAnswer.ToString().ToUpper() == answer.answer.ToString().ToUpper()) { totalResult += point_per_question; } } ExamResult exam_result = new ExamResult { exam = thisExam, student = thisStudent, students_answers = _students_answers.TrimEnd(','), correct_answers = _correct_answers.TrimEnd(','), teacher = thisExam.teacher, result = totalResult }; Database.Session.Save(exam_result); Database.Session.Flush(); }
public Response.Response <int> answerQuizeQuestion(question_answer obj) { Response.Response <int> response = new Response.Response <int>(); //check if user is already answer this qestion befor bool answered = _service.checkIdQuestionAnswered(obj.questionId.Value, obj.userId.Value); //if not answered before add new answer if (!answered) { var result = _service.answerQuizeQuestion(obj); response.Result = result; response.StatusCode = 200; } //if answered update existing answer else { var result = _service.updateAnswerQuizeQuestion(obj); response.Result = result; response.StatusCode = 200; } return(response); }
/// <summary> /// aswer question /// </summary> /// <param name="obj"></param> /// <returns></returns> public int answerQuizeQuestion(question_answer obj) { context.question_answer.Add(obj); context.SaveChanges(); return(obj.Id); }
public void MarkAsModified(question_answer item) { }