} // end CorrectExam public ActionResult Correct(CorrectingViewModel viewmodel) { int id = viewmodel.Answer.AnswerId; StudentAnswer studentAnswer = db.StudentAnswers.Find(id); //studentAnswer.ExaminerComments = viewmodel.Answer.ExaminerComments; if (studentAnswer == null) { return(RedirectToAction("CorrectExam", "Examiner", new { subject = viewmodel.Subject })); } studentAnswer.ExaminerComments = viewmodel.Answer.ExaminerComments; studentAnswer.MarksGained = viewmodel.Answer.MarksGained; studentAnswer.CorrectedDateTime = viewmodel.Answer.CorrectedDateTime; studentAnswer.CorrectorId = viewmodel.Answer.CorrectorId; db.Entry(studentAnswer).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("CorrectExam", "Examiner", new { subject = viewmodel.Subject })); //return RedirectToAction("Examiner", "Dashboard"); }
private List <StudentAnswer> AddStudentAwnser() { List <StudentAnswer> lxStudAnwer = new List <StudentAnswer>(); StudentAnswer xStudA = new StudentAnswer() { StudentTestFk = 1, Question = 1, Answer = 1, }; StudentAnswer xStudA2 = new StudentAnswer() { StudentTestFk = 1, Question = 2, Answer = 1, }; StudentAnswer xStudA3 = new StudentAnswer() { StudentTestFk = 1, Question = 3, Answer = 1, }; StudentAnswer xStudA4 = new StudentAnswer() { StudentTestFk = 1, Question = 3, Answer = 2, }; lxStudAnwer.Add(xStudA); lxStudAnwer.Add(xStudA2); lxStudAnwer.Add(xStudA3); lxStudAnwer.Add(xStudA4); return(lxStudAnwer); }
public JsonResult SaveStudentAnswer(StudentAnswer objStudentAnswer) { List <StudentAnswer> canAnswer = Session["StdQuestionAnswer"] as List <StudentAnswer>; if (objStudentAnswer.AnswerText != null) { List <StudentAnswer> objstudentAnswers = Session["StdQuestionAnswer"] as List <StudentAnswer>; if (objstudentAnswers == null) { objstudentAnswers = new List <StudentAnswer>(); } objstudentAnswers.Add(objStudentAnswer); Session["StdQuestionAnswer"] = objstudentAnswers; } //System.Diagnostics.Debug.WriteLine(" canAnswer " + canAnswer.Count); foreach (var item in canAnswer) { Result objResult = new Result(); objResult.AnswerText = item.AnswerText; objResult.ResQuesId = item.QuestionID; objResult.ResStudent = Convert.ToInt32(Session["StudentID"]); db.Results.Add(objResult); db.SaveChanges(); } return(Json(data: new { message = "Answer Successfully Added.", success = true }, JsonRequestBehavior.AllowGet)); }
public void Delete(int id) { StudentAnswer studentAnswer = _db.StudentAnswers.Find(id); if (studentAnswer != null) { _db.StudentAnswers.Remove(studentAnswer); } }
public async Task <ActionResult> DeleteConfirmed(int id) { StudentAnswer studentAnswer = await db.StudentAnswers.FindAsync(id); db.StudentAnswers.Remove(studentAnswer); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
protected void questionsGridView_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { string questionID = questionsGridView.DataKeys[e.Row.RowIndex].Value.ToString(); var answers = (List <StudentAnswer>)Session["studentAnswers"]; var answer = answers.SingleOrDefault(x => x.Qstn_Id == questionID); if (answer == null) { answer = new StudentAnswer() { Exam_Id = Session["examId"].ToString(), Qstn_Id = questionID }; answers.Add(answer); } GridView choicesGrid = (GridView)e.Row.FindControl("choicesGridView"); SqlDataSource source = (SqlDataSource)e.Row.FindControl("ChoicesDS"); source.SelectCommand = $"select * from Choice where Qstn_Id = {questionID};"; choicesGrid.DataBind(); if (choicesGrid.Rows.Count == 0) { DataTable dataTable = new DataTable(); dataTable.Columns.Add("Chc_Id"); dataTable.Columns.Add("Chc_Text"); dataTable.Columns.Add("Qstn_Id"); DataRow row = dataTable.NewRow(); row[0] = 0; row[1] = "TRUE"; row[2] = questionID; dataTable.Rows.Add(row); row = dataTable.NewRow(); row[0] = 1; row[1] = "FALSE"; row[2] = questionID; dataTable.Rows.Add(row); choicesGrid.DataSourceID = null; choicesGrid.DataSource = dataTable; choicesGrid.DataBind(); } if (!string.IsNullOrEmpty(answer.Qstn_stAnswerIndex)) { choicesGrid.SelectRow(int.Parse(answer.Qstn_stAnswerIndex)); } var lblAnswer = (Label)e.Row.FindControl("lblAnswer"); if ((bool)Session["complete"]) { lblAnswer.Visible = true; lblAnswer.Text = "Answer " + questionsGridView.DataKeys[e.Row.RowIndex].Values[1].ToString(); } else { lblAnswer.Visible = false; } } }
public ServiceResponse <StudentAnswer> Add(StudentAnswer StudentAnswer) { var response = new ServiceResponse <StudentAnswer>(); if (response.Validation(new StudentAnswerValidation().Validate(StudentAnswer))) { response.Result = StudentAnswerRepository.Insert(StudentAnswer); } return(response); }
public bool RulesTests_IsStudent(bool value) { var studentAnswer = new StudentAnswer(value); var under18 = new StudentRule(); return(under18.Execute(new Answers { StudentAnswer = studentAnswer })); }
public void Update(StudentAnswer studentanswer) { //studentanswer.SAID = SAID; studentanswer.QuestionID = QuestionID; studentanswer.Username = Username; studentanswer.Answer = Answer; studentanswer.Flagged = Flagged; studentanswer.Type = Type; studentanswer.StudentAnswerActive = StudentAnswerActive; studentanswer.MarkObtained = MarkObtained; }
public void AddStudentAnswer(StudentAnswerDto studentAnswer) { StudentAnswer answer = new StudentAnswer() { StudentAnswerId = studentAnswer.StudentAnswerGuid, Answer = _database.Answers.Get(studentAnswer.AnswerId), Question = _database.Questions.Get(studentAnswer.QuestionId), User = _database.Users.Get(studentAnswer.UserId) }; _database.StudentAnswers.Create(answer); _database.Save(); }
public ActionResult StartExam(QuestionAttemptVm m) { var question = db.ExamQuestions.Where(a => a.Id == m.QuestionId).SingleOrDefault(); var stanswer = db.StudentAnswers.Where(a => a.QuestionId == m.QuestionId && a.StudentExamNo == m.StudentExamNo).FirstOrDefault(); if (stanswer != null) { // // has already attemted this question return(RedirectToAction("StartExam", new { page = m.CurrentPageNo, error = "You Have Already Answered this question please answer another one" })); } if (question != null) { var client = new RestClient("https://api.dandelion.eu/datatxt/sim/v1"); var request = new RestRequest(); request.AddParameter("text1", m.Answer); request.AddParameter("text2", question.Answer); request.AddParameter("token", "19512dc20d8549b592425d177fc0f132"); var response = client.Execute(request); if (response.StatusCode == System.Net.HttpStatusCode.OK) { JsonDeserializer deserial = new JsonDeserializer(); var obj = deserial.Deserialize <TextSimilarityApi>(response); bool correct = false; if (obj.similarity >= 0.400) { correct = true; } var score = Convert.ToDecimal(obj.similarity) * question.Point; var answer = new StudentAnswer { Answer = m.Answer, IsCorrect = correct, PrecisionLevel = Convert.ToDecimal(obj.similarity), QuestionId = m.QuestionId, StudentExamNo = m.StudentExamNo, StudentId = m.StudentId, Score = score }; db.StudentAnswers.Add(answer); db.SaveChanges(); var next = m.CurrentPageNo + 1; return(RedirectToAction("StartExam", new { page = next })); } return(RedirectToAction("StartExam", new { page = m.CurrentPageNo, error = "Unable to submit request" })); } return(RedirectToAction("StartExam", new { page = m.CurrentPageNo, error = "Something Went Wrong" })); }
public async Task <ActionResult> Edit([Bind(Include = "AnswerId,EnrollmentId,PaperQuestionId,CorrectorId,Answer,ExaminerComments,MarksGained,CorrectedDateTime,CommittedByStudent")] StudentAnswer studentAnswer) { if (ModelState.IsValid) { db.Entry(studentAnswer).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.CorrectorId = new SelectList(db.Users, "Id", "FirstName", studentAnswer.CorrectorId); ViewBag.EnrollmentId = new SelectList(db.Enrollments, "EnrollmentId", "StudentId", studentAnswer.EnrollmentId); ViewBag.PaperQuestionId = new SelectList(db.PaperQuestions, "PaperQuestionId", "ExamId", studentAnswer.PaperQuestionId); return(View(studentAnswer)); }
// GET: StudentAnswers/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentAnswer studentAnswer = await db.StudentAnswers.FindAsync(id); if (studentAnswer == null) { return(HttpNotFound()); } return(View(studentAnswer)); }
// GET: StudentAnswers public async Task <ActionResult> Correct(StudentAnswer answer, string getsubject) { if (answer == null) { return(RedirectToAction("Examiner", "Dashboard")); } StudentAnswer studentAnswer = await db.StudentAnswers.FindAsync(answer.AnswerId); studentAnswer = answer; db.Entry(studentAnswer).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("CorrectExam", "Examiner", new{ subject = getsubject })); }
public IActionResult Answer([FromBody] List <AnswerQuestion> answerQuestion) { //var studnetId = AuthoticateUserId(); foreach (var item in answerQuestion) { StudentAnswer sa = new StudentAnswer() { Answer = item.Answer, QuestionId = item.Id, StudentId = item.UserId }; this.Context.Add(sa); } this.Context.SaveChanges(); return(Ok()); }
// GET: StudentAnswers/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } StudentAnswer studentAnswer = await db.StudentAnswers.FindAsync(id); if (studentAnswer == null) { return(HttpNotFound()); } ViewBag.CorrectorId = new SelectList(db.Users, "Id", "FirstName", studentAnswer.CorrectorId); ViewBag.EnrollmentId = new SelectList(db.Enrollments, "EnrollmentId", "StudentId", studentAnswer.EnrollmentId); ViewBag.PaperQuestionId = new SelectList(db.PaperQuestions, "PaperQuestionId", "ExamId", studentAnswer.PaperQuestionId); return(View(studentAnswer)); }
public override void Import(SnappetChallengeContext context) { var assembly = Assembly.GetExecutingAssembly(); const string resourceName = "SnappetChallenge.DAL.DataImport.work.json"; // serialized JSON is embedded resource var itemsToInsert = new List<StudentAnswer>(); using (var streamFromEmbeddedResource = assembly.GetManifestResourceStream(resourceName)) using (var sr = new StreamReader(streamFromEmbeddedResource)) using (var reader = new JsonTextReader(sr)) { while (reader.Read()) { if (reader.TokenType != JsonToken.StartObject) continue; var obj = JObject.Load(reader); var studentAnswer = new StudentAnswer { Correct = obj["Correct"].Value<int>() == 1, // explicit cast to bool DateAdded = DateTime.Now, Difficulty = obj["Difficulty"].Value<string>().Equals("NULL") // handle weird NULL values, they serialize as string "NULL" ? null : obj["Difficulty"].Value<double?>(), Domain = obj["Domain"].Value<string>(), ExerciseId = obj["ExerciseId"].Value<long>(), LearningObjective = obj["LearningObjective"].Value<string>(), Progress = obj["Progress"].Value<int>(), Subject = obj["Subject"].Value<string>(), SubmitDateTime = obj["SubmitDateTime"].Value<DateTime>(), SubmittedAnswerId = obj["SubmittedAnswerId"].Value<long>(), UserId = obj["UserId"].Value<long>(), Id = obj["SubmittedAnswerId"].Value<long>() // this is doubled in SubmittedAnswerId.. }; itemsToInsert.Add(studentAnswer); } } context.BulkInsert(itemsToInsert); context.SaveChanges(); }
/// <summary> /// Loads The Review Quiz View, with the relevant Quiz Information /// </summary> /// <param name="StudentQuizID">ID of Student Quiz</param> /// <param name="ClassID">ID of Class</param> /// <returns>The Review Quiz View</returns> public ActionResult ReviewQuiz(int StudentQuizID, int ClassID) { if (test(ClassID) != null) { return(test(ClassID)); } StudentVM student = getSVM(ClassID); StudentQuizze StudentQuiz = db.StudentQuizzes.Where(sq => sq.SQID == StudentQuizID).FirstOrDefault(); Quizze Quiz = db.Quizzes.Where(q => q.QuizID == StudentQuiz.QuizID).FirstOrDefault(); List <QuizQuestion> Questions = db.QuizQuestions.Where(q => q.QuizID == Quiz.QuizID).ToList(); student.ReviewQuestions = new List <QuizReview>(); MultChoiceAnswer Answer = null; QuizReview ReviewQuestion = null; StudentAnswer SAnswer = null; student.Quiz = Quiz; foreach (QuizQuestion Q in Questions) { ReviewQuestion = new QuizReview(); ReviewQuestion.QuestionText = Q.QuestionText; ReviewQuestion.Points = Q.Points; ReviewQuestion.QuestionID = Q.QuestionID; SAnswer = db.StudentAnswers.Where(sa => sa.QuestionID == Q.QuestionID && sa.SQID == StudentQuiz.SQID).FirstOrDefault(); Answer = db.MultChoiceAnswers.Where(a => a.QuestionID == Q.QuestionID).FirstOrDefault(); ReviewQuestion.StudentPoints = SAnswer.StudentPoints; ReviewQuestion.StudentAnswer = SAnswer.AnswerNumber; ReviewQuestion.Answer1 = Answer.Answer1; ReviewQuestion.Answer2 = Answer.Answer2; ReviewQuestion.Answer3 = Answer.Answer3; ReviewQuestion.Answer4 = Answer.Answer4; ReviewQuestion.CorrectAnswer = Answer.CorrectAnswer; student.ReviewQuestions.Add(ReviewQuestion); } return(View("ReviewQuiz", "_StudentLayout", student)); }
public ServiceResponse <StudentAnswer> Update(StudentAnswer StudentAnswer) { var response = new ServiceResponse <StudentAnswer>(); if (response.Validation(new StudentAnswerValidation().Validate(StudentAnswer))) { StudentAnswerRepository.Detach(StudentAnswer); var repositoryResponse = StudentAnswerRepository.GetById(StudentAnswer.Id); if (repositoryResponse != null) { repositoryResponse.StudentId = StudentAnswer.StudentId; response.Result = StudentAnswerRepository.Update(repositoryResponse); } else { response.SetError("Veri Bulunamadı"); } } return(response); }
public async Task <IActionResult> AddAnswer(StudentAnswer answer) { var question = await _context.Questions.Where(m => m.Id == answer.QuestionId).FirstOrDefaultAsync(); var loggedInUser = await _userManager.FindByNameAsync(HttpContext.User.Identity.Name); var student = await _context.Students.Where(m => m.ApplicationUserId == loggedInUser.Id).FirstOrDefaultAsync(); if (answer.Id == 0) { answer.StudentId = student.Id; answer.Status = 0; _context.Add(answer); await _context.SaveChangesAsync(); } else { answer.StudentId = student.Id; _context.Update(answer); await _context.SaveChangesAsync(); } return(RedirectToAction("ParticipateInExam", new { examId = question.ExamId })); }
public void UpdateAnswer(string name, int questionId, string answer) { using (var db = new QuizBucketContext()) { int userId = db.Students.Where(s => s.StudentName == name).Select(i => i.StudentId).FirstOrDefault(); var StudentAnswerExists = db.StudentAnswers.Where(s => s.StudentId == userId && s.QuestionId == questionId).FirstOrDefault(); if (StudentAnswerExists == null) { var addAnswer = new StudentAnswer { StudentId = userId, QuestionId = questionId, Answer = answer }; db.StudentAnswers.Add(addAnswer); } else { StudentAnswerExists.Answer = answer; } db.SaveChanges(); } }
public static ProcessedAS ProcessAS(Bitmap img) { if (img.Width != Constant.AS_WIDTH || img.Height != Constant.AS_HEIGHT) { img = CommonImageProcessing.ResizeImage(img, Constant.AS_WIDTH, Constant.AS_HEIGHT); } Bitmap orgImg = img; img = PreProcess(img); Rect topRightRect = DetectTopRightFlagRect(img); Rect bottomRightRect = DetectBottomRightCorner(img); List <Rect> verticalFlagRects = GetVerticalFlagRect(topRightRect, img); List <Rect> aboveHorizontalFlagRects = GetAboveHorizontalFlagRect(topRightRect, img); List <Rect> belowHorizontalFlagRects = GetBelowHorizontalFlagRect(bottomRightRect, img); Tuple <String, List <Circle> > studentCodeResult = DetectStudentCode(img, belowHorizontalFlagRects, verticalFlagRects); Tuple <String, List <Circle> > examCodeResult = DetectExamCode(img, belowHorizontalFlagRects, verticalFlagRects); Tuple <List <Char>, List <Circle>, List <Point> > studentAnswersResult = DetectStudentAnswer(img, aboveHorizontalFlagRects, verticalFlagRects); String examId = examCodeResult.Item1; String studentId = studentCodeResult.Item1; ProcessedAS processedAS = new ProcessedAS(); processedAS.examId = examId; processedAS.studentId = studentId; StudentAnswer studentAnswer; int numberOfQuestion = Globals.numberOfQuestion; List <Char> answerText = studentAnswersResult.Item1; List <Point> positions = studentAnswersResult.Item3; List <StudentAnswer> studentAnswers = new List <StudentAnswer>(); for (int i = 1; i <= numberOfQuestion; i++) { Point p = positions[i]; // 300 x 38 // CvInvoke.Rectangle(outputImg, rect, new MCvScalar(255, 0, 255), 2); studentAnswer = new StudentAnswer(answerText[i], new Point(p.x - 45, p.y - 18)); studentAnswers.Add(studentAnswer); } processedAS.answers = studentAnswers; //List<Circle> tmp; //tmp = studentCodeResult.Item2; //Image<Bgr, Byte> outputImg = new Image<Bgr, Byte>(img); //foreach (Circle circle in tmp) //{ // CvInvoke.Circle(outputImg, new System.Drawing.Point(circle.center.x, circle.center.y), circle.radius - 2, new MCvScalar(0, 255, 0), 2); //} //tmp = examCodeResult.Item2; //foreach (Circle circle in tmp) //{ // CvInvoke.Circle(outputImg, new System.Drawing.Point(circle.center.x, circle.center.y), circle.radius - 2, new MCvScalar(0, 255, 0), 2); //} //tmp = studentAnswersResult.Item2; //foreach (Circle circle in tmp) //{ // CvInvoke.Circle(outputImg, new System.Drawing.Point(circle.center.x, circle.center.y), circle.radius-2, new MCvScalar(0, 255, 0), 2); //} processedAS.processedAnswerSheetImage = orgImg; return(processedAS); }
private void Initialize(int aid) { try { StringBuilder html = new StringBuilder(); StudentAnswer stdAns = new StudentAnswer(); Assessment ass = new Assessment(); Collection<StudentAnswer> stdAnsList=stdAns.GetStudentAnswerByAOID(aid); ass=ass.GetAssessmentByOID(aid); html.Append("<table border='0' cellspacing='0' cellpadding='0'><tr> <td bgcolor='#000000'>"); html.Append("<table bgcolor='#000000' cellspacing='1' cellpadding='0' >"); html.Append("<tr>"); html.Append("<td bgcolor='#FFFFFF'> </td><td bgcolor='#FFFFFF'> </td>"); foreach (Section s in ass.SectionList) { html.Append("<td bgcolor='#FFFFFF'>"); html.Append(s.SectionName); html.Append("</td>"); } html.Append("</tr>"); //Second Row html.Append("<tr>"); html.Append("<td bgcolor='#FFFFFF'>Student Name</td><td bgcolor='#FFFFFF'>Banner ID</td>"); // foreach (Section s in ass.SectionList) { html.Append("<td bgcolor='#FFFFFF'>"); html.Append("<table bgcolor='#000000' cellspacing='1' cellpadding='4'>"); html.Append("<tr>"); int i = 1; foreach (Question q in s.QuestionList) { html.Append("<td bgcolor='#FFFFFF'>"); html.Append(i++.ToString()); html.Append("</td>"); } html.Append("</tr>"); html.Append("</table>"); html.Append("</td>"); } // html.Append("</tr>"); //Third Row and onward var StdList = from stans in stdAnsList group stans.StudentName by new {stans.StudentName,stans.BannerID} into g select g; //for (int j = 0; j < StdList.Count; j++) int j = 0; foreach (var stName in StdList) { html.Append("<tr>"); html.Append("<td bgcolor='#FFFFFF' >" + stName.Key.StudentName + "</td><td bgcolor='#FFFFFF'>" + stName.Key.BannerID + "</td>"); // foreach (Section s in ass.SectionList) { html.Append("<td bgcolor='#FFFFFF'>"); html.Append("<table bgcolor='#000000' cellspacing='1' cellpadding='4'>"); html.Append("<tr>"); foreach (Question q in s.QuestionList) { if (stdAnsList.Count == 0) { html.Append("<td bgcolor='#FFFFFF'> </td>"); continue; } stdAns = stdAnsList[j++]; if (stdAns.questionOID == q.QuestionOID && stdAns.SectionOID == s.SectionOID) { if (stdAns.IsRight == 1) { html.Append("<td bgcolor='#FFFFFF'>"); } else { html.Append("<td bgcolor='#FF0000'>"); } //html.Append(q.OrderNo); html.Append(stdAns.Response); html.Append("</td>"); } else { j--; html.Append("<td bgcolor='#FFFFFF'> </td>"); } } html.Append("</tr>"); html.Append("</table>"); html.Append("</td>"); } // html.Append("</tr>"); } //END third html.Append("</table>"); html.Append(" </td></tr></table>"); Response.Write(html); //html.Remove(0, html.Length); } catch (Exception ex) { } }
//[ValidateAntiForgeryToken] public async Task <ActionResult> Answer([Bind(Include = "AnswerId,EnrollmentId,PaperQuestionId,Answer,CommittedByStudent")] StudentAnswer studentAnswer) { string username = (string)Session["Username"]; string[] usernameCheck = studentAnswer.EnrollmentId.Split('-'); if (usernameCheck[0] == username) { string exam = (from d in db.PaperQuestions where d.PaperQuestionId == studentAnswer.PaperQuestionId select d.ExamId).SingleOrDefault(); // we get the paperquestions for this exam in a list List <PaperQuestion> paper = db.PaperQuestions.Where(x => x.ExamId == exam).ToList(); //now we generate a list of QuestionId found in the list above IEnumerable <int> SpecificQuestions = from p in paper select p.QuestionId; //and we select those Questions that match the QuestionIds List <Question> questionList = new List <Question>(from q in db.Questions where SpecificQuestions.Contains(q.QuestionId) select q); //now we get the multiple choices we need for this exam List <MultipleChoice> multichoiceList = new List <MultipleChoice>(from m in db.MultipleChoices where SpecificQuestions.Contains(m.QuestionId) select m); ViewBag.MultiChoices = multichoiceList; ViewBag.Questions = questionList; ViewBag.PaperQuestions = paper; //we get the StudentAnswers that concern us only string[] idSplit = exam.Split('-'); username = username + "-" + idSplit[0]; IEnumerable <string> specificPaperQuestions = from p in paper select p.PaperQuestionId; List <StudentAnswer> answerList = new List <StudentAnswer>(from q in db.StudentAnswers where specificPaperQuestions.Contains(q.PaperQuestionId) select q); List <StudentAnswer> specificAnswerList = answerList.Where(x => x.EnrollmentId == username).ToList(); ViewBag.Answers = specificAnswerList; ViewData["ExamId"] = exam; //now we get the subject string subjectid = (from q in questionList select q.SubjectId).FirstOrDefault(); ViewBag.Subject = subjectid; if (ModelState.IsValid) { //check that student is really enrolled if (db.Enrollments.Find(username) != null) { StudentAnswer newStudentAnswer = db.StudentAnswers .Where(x => x.EnrollmentId == studentAnswer.EnrollmentId) .Where(x => x.PaperQuestionId == studentAnswer.PaperQuestionId).FirstOrDefault(); if (newStudentAnswer != null) { studentAnswer.AnswerId = newStudentAnswer.AnswerId; } db.StudentAnswers.AddOrUpdate(studentAnswer); await db.SaveChangesAsync(); } else { return(HttpNotFound()); } } } else { return(HttpNotFound()); } return(View("Index")); }
public ActionResult AutoCorrectMC(string session) {// this function recieves the session for which all Written Answers have been corrected // it then automatically corrects Multiple CHoice questions // finally marking the exam as fully corrected //first we get the MultipleChoice PaperQuestions for the session List <PaperQuestion> paperquestions = new List <PaperQuestion>(from q in db.PaperQuestions where q.ExamId == session && q.RelatedQuestion.QuestionFormat == Question.QuestionType.MultipleChoice select q); List <string> paperquestionid = new List <string>(from q in paperquestions select q.PaperQuestionId); // List<int> questionid = new List<int>(from q in paperquestions select q.QuestionId); //then we get the StudentAnswers that match the paperquestions. These need to be corrected List <StudentAnswer> answers = new List <StudentAnswer>(from a in db.StudentAnswers where paperquestionid.Contains(a.PaperQuestionId) && a.CorrectedDateTime == null select a); // now we update each of them depending on the student's answer and whether it corresponds to the right answer if (answers.Count != 0) { StudentAnswer temp = new StudentAnswer(); foreach (StudentAnswer ans in answers) { temp = db.StudentAnswers.Find(ans.AnswerId); temp.CorrectedDateTime = DateTime.Now; temp.ExaminerComments = "Corrected Automatically"; int correctAnswer = (int)(from m in db.MultipleChoices where (ans.RelatedPaperQuestion.QuestionId == m.QuestionId) select m.CorrectChoice).SingleOrDefault(); if (ans.Answer == correctAnswer.ToString()) { temp.MarksGained = ans.RelatedPaperQuestion.MarksAllocated; } else { temp.MarksGained = 0; } db.Entry(temp).State = EntityState.Modified; db.SaveChanges(); } //end for } //end if //now we take all answers for this exam session to calculate the student's total answers = new List <StudentAnswer>(from a in db.StudentAnswers where a.RelatedPaperQuestion.RelatedExamSession.ExamId == session select a); Enrollment enrollment = new Enrollment(); foreach (StudentAnswer ans in answers) { enrollment = ans.RelatedEnrollment; if (enrollment.ExamMark == null) { enrollment.ExamMark = 0; } int a = (int)enrollment.ExamMark; int b = ans.MarksGained; int c = a + b; enrollment.ExamMark = (byte)c; db.Entry(enrollment).State = EntityState.Modified; db.SaveChanges(); } //now we make sure all Enrollment's FinalAssesment is updated, including those students that were absent //Absent students have their enrollment pending or Absent and have produced no StudentAnswer string subject = (from x in db.ExamSessions where x.ExamId == session select x.SubjectId).FirstOrDefault(); IEnumerable <Enrollment> enrollments = new List <Enrollment>(from e in db.Enrollments where e.SubjectId == subject && e.FinalAssessment < Enrollment.Assessment.Passed select e); foreach (Enrollment e in enrollments) { enrollment = e; if (enrollment.FinalAssessment == Enrollment.Assessment.Pending || enrollment.FinalAssessment == Enrollment.Assessment.Absent) { enrollment.ExamMark = 0; enrollment.SessionStatus = Enrollment.Status.Confirmed; enrollment.FinalAssessment = Enrollment.Assessment.Absent; } if (enrollment.ExamMark == null) { enrollment.ExamMark = 0; } if (enrollment.ExamMark >= 45) { enrollment.FinalAssessment = Enrollment.Assessment.Passed; } else { enrollment.FinalAssessment = Enrollment.Assessment.Failed; } db.Entry(enrollment).State = EntityState.Modified; db.SaveChanges(); } //now we find the MAX mark and other stats using only those who sat for the exam enrollments = new List <Enrollment>(from a in answers select a.RelatedEnrollment).Distinct(); byte? max = (from e in enrollments select e.ExamMark).Max(); byte? min = (from e in enrollments select e.ExamMark).Min(); List <byte?> allmarks = new List <byte?> (from e in enrollments select e.ExamMark); float sum = 0; float count = 0; int fails = 0; foreach (byte?m in allmarks) { if (m != null) { sum = sum + (float)m; } else { sum = sum + 0; } count++; if (m < 45) { fails++; } } if (count == 0) { count = 1; //avoiding DIV by zero case; } float avg = sum / count; //Now we add the found details and mark the exam as fully corrected ExamSession exam = db.ExamSessions.Find(session); if (exam == null) { return(RedirectToAction("Examiner", "Dashboard")); } if (max != null) { exam.MaxMark = (byte)max; } else { exam.MaxMark = 0; } if (min != null) { exam.MinMark = (byte)min; } else { exam.MinMark = 0; } exam.AvgMark = avg; exam.NumOfParticipants = (int)count; exam.NumOfFails = fails; exam.FullyCorrected = true; db.Entry(exam).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("ExamDone", new { id = subject })); }
public void Update(StudentAnswer item) { _db.Entry(item).State = System.Data.Entity.EntityState.Modified; }
public void Create(StudentAnswer item) { _db.StudentAnswers.Add(item); }
public Collection<StudentAnswer> GetStudentAnswerByAOID(int AOID) { Collection<StudentAnswer> answerList = new Collection<StudentAnswer>(); StudentAnswer stdAns; using (OdbcConnection connection = new OdbcConnection(connectionString)) { using (OdbcCommand command = new OdbcCommand()) { command.Connection = connection; command.CommandText = "{CALL StudentRespWithAnswer_ByAOID(?)}"; command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@AOID",AOID); connection.Open(); using (OdbcDataReader dataReader = command.ExecuteReader()) { while (dataReader.Read()) { stdAns = new StudentAnswer(); stdAns.IsRight = Convert.ToInt32(dataReader["IsRight"]); stdAns.questionOID = Convert.ToInt32(dataReader["questionOID"]); stdAns.Response = Convert.ToString(dataReader["Response"]); stdAns.SectionOID = Convert.ToInt32(dataReader["SectionOID"]); stdAns.StudentName = Convert.ToString(dataReader["StudentName"]); stdAns.BannerID = Convert.ToString(dataReader["BannerID"]); answerList.Add(stdAns); } } } } return answerList; }
public void RemoveStudentAnswer(StudentAnswer a) { }
public void AddStudentAnswer(StudentAnswer a) { }
private void Initialized(int aid) { try { string colsp = ""; int i = 0; StringBuilder html = new StringBuilder(); StudentAnswer stdAns = new StudentAnswer(); Assessment ass = new Assessment(); Collection<StudentAnswer> stdAnsList = stdAns.GetStudentAnswerByAOID(aid); ass = ass.GetAssessmentByOID(aid); html.Append("<table border='0' cellspacing='0' cellpadding='0'><tr> <td bgcolor='#000000'>"); html.Append("<table bgcolor='#000000' cellspacing='1' cellpadding='4' >"); //First Row html.Append("<tr>"); html.Append("<td bgcolor='#FFFFFF' colspan='2' > </td>"); foreach (Section s in ass.SectionList) { i = s.QuestionList.Count == 0 ? 1 : s.QuestionList.Count; colsp = "colspan='" + i+"'"; html.Append("<td bgcolor='#CDCABB' " + colsp + " >"); html.Append(s.SectionName); html.Append("</td>"); } html.Append("</tr>"); //Second Row html.Append("<tr>"); html.Append("<td bgcolor='#CDCABB'>Student Name</td><td bgcolor='#CDCABB'>Banner ID</td>"); // foreach (Section s in ass.SectionList) { i = 1; foreach (Question q in s.QuestionList) { html.Append("<td bgcolor='#CDCABB'>"); html.Append(i++.ToString()); html.Append("</td>"); } } html.Append("</tr>"); //Third Row and onword var StdList = from stans in stdAnsList group stans.StudentName by new { stans.StudentName, stans.BannerID } into g select g; //for (int j = 0; j < StdList.Count; j++) int j = 0; foreach (var stName in StdList) { html.Append("<tr>"); html.Append("<td bgcolor='#FFFFFF' >" + stName.Key.StudentName + "</td><td bgcolor='#FFFFFF'>" + stName.Key.BannerID + "</td>"); // foreach (Section s in ass.SectionList) { //html.Append("<td bgcolor='#FFFFFF'>"); //html.Append("<table bgcolor='#000000' cellspacing='1' cellpadding='4'>"); //html.Append("<tr>"); foreach (Question q in s.QuestionList) { if (stdAnsList.Count == 0) { html.Append("<td bgcolor='#FFFFFF'> </td>"); continue; } //stdAns = stdAnsList[j++]; StudentAnswer stdAns1 = null; var t = from ans in stdAnsList where ans.questionOID == q.QuestionOID && ans.SectionOID == s.SectionOID && ans.BannerID == stName.Key.BannerID select ans; foreach (StudentAnswer m in t) { stdAns1 = m; break; } if (stdAns1 == null) { html.Append("<td bgcolor='#FFFFFF'> </td>"); continue; } // StudentAnswer stdAns1 =stdAnsList. if (stdAns1.questionOID == q.QuestionOID && stdAns1.SectionOID == s.SectionOID) { if (stdAns1.IsRight == 1) { html.Append("<td bgcolor='#FFFFFF'>"); } else { html.Append("<td bgcolor='#FF0000'>"); } //html.Append(q.OrderNo); html.Append(stdAns1.Response); html.Append("</td>"); } else { j--; html.Append("<td bgcolor='#FFFFFF'> </td>"); } } //html.Append("</tr>"); //html.Append("</table>"); //html.Append("</td>"); } // html.Append("</tr>"); } html.Append("</table>"); html.Append(" </td></tr></table>"); Response.Write(html); } catch (Exception ex) { } }
public void RemoveStudentAnswer(StudentAnswer a) { db.StudentAnswers.Remove(a); }
private void nextBtn_Click(object sender, EventArgs e) { if (count <= (examQuestions.Count - 1)) { StudentAnswer sa = new StudentAnswer(); int type = examQuestions[count].Question.Type; sa.Q = examQuestions[count].Question; //sa.Q.Type = type; //sa.S = StudentDAL.GetById(student_id); sa.S = MyStudent.Student; sa.Solved = true; //how to get the exam sa.E = MyExam.Exam; switch (type) { case 1: if (!choiceA.Checked && !choiceB.Checked && !choiceC.Checked && !choiceD.Checked) { MessageBox.Show("Please choose the correct answer"); } else { //how to get the answer from the question QuestionAnswer answer1 = examQuestions[count].Question.Answers[0]; QuestionAnswer answer2 = examQuestions[count].Question.Answers[1]; QuestionAnswer answer3 = examQuestions[count].Question.Answers[2]; QuestionAnswer answer4 = examQuestions[count].Question.Answers[3]; sa.Qa = new QuestionAnswer(); if (choiceA.Checked) { sa.Qa.Answer = choiceALabel.Text; } else if (choiceB.Checked) { sa.Qa.Answer = choiceBLabel.Text; } else if (choiceC.Checked) { sa.Qa.Answer = choiceCLabel.Text; } else { sa.Qa.Answer = choiceDLabel.Text; } } break; case 2: if (!checkTrue.Checked && !checkFalse.Checked) { MessageBox.Show("Please choose the correct answer"); } else { QuestionAnswer trueAnswer = examQuestions[count].Question.Answers[0]; QuestionAnswer falseAnswer = examQuestions[count].Question.Answers[1]; sa.Qa = new QuestionAnswer(); if (checkTrue.Checked) { sa.Qa.Answer = checkTrueLabel.Text; } else if (checkFalse.Checked) { sa.Qa.Answer = checkFalseLabel.Text; } } break; case 3: if (String.IsNullOrEmpty(questionAnswer.Text)) { MessageBox.Show("Please add the answer"); } else { QuestionAnswer essayAnswer = examQuestions[count].Question.Answers[0]; essayAnswer.Answer = questionAnswer.Text; sa.Qa = new QuestionAnswer(); sa.Qa.Answer = questionAnswer.Text; } break; } //add in Student_Question_Exam StudentAnswerDAL.Add(sa); if (++count <= (examQuestions.Count - 1)) { showQuestion(count); } } }
public void AddStudentAnswer(StudentAnswer a) { db.StudentAnswers.Add(a); }