public JUserQuizQuestionAnswer UserQuizQuestionAnswerToJModel(UserQuizQuestionAnswer uqqa) { JUserQuizQuestionAnswer juqqa = new JUserQuizQuestionAnswer(); juqqa.id = uqqa.id; juqqa.quizId = uqqa.quizId; juqqa.questionId = uqqa.questionId; juqqa.answerId = uqqa.answerId; juqqa.userId = uqqa.userId; juqqa.text = uqqa.text; if (uqqa.isChecked != null) { juqqa.isChecked = (bool)uqqa.isChecked; } else { juqqa.isChecked = false; } if (uqqa.isApproved != null) { juqqa.isApproved = (bool)uqqa.isApproved; } else { juqqa.isApproved = false; } return(juqqa); }
public ActionResult SubmitGrade(GradingDecision[] decisions) { UserViewModel vmUser = session.getSessionUser(); if (vmUser == null) { if (!val.getUserCredentials(Request)) { return(RedirectToAction("Login", "Home")); } vmUser = session.getSessionUser(); } Queries query = new Queries(); User user = query.getUserBySam(vmUser.modelToUser(session.getSessionUser()).SAMAccountName); List <UserQuizQuestionAnswer> uqqas = new List <UserQuizQuestionAnswer>(); foreach (GradingDecision decision in decisions) { UserQuizQuestionAnswer uqqa = new UserQuizQuestionAnswer(); uqqa.quizId = decision.quizId; uqqa.userId = decision.userId; uqqa.questionId = decision.questionId; uqqa.isApproved = decision.isApproved; uqqas.Add(uqqa); } List <UserQuizQuestionAnswer> addedUqqas = new List <UserQuizQuestionAnswer>(); addedUqqas = query.submitQuiz(uqqas); if (addedUqqas.Count > 0) { return(Json("Grading Completed", JsonRequestBehavior.AllowGet)); } return(Json("Failed to submit grades", JsonRequestBehavior.AllowGet)); }
public Answer getUserAnswerByQuestionId(int userId, int questionId) { DBContext db = new DBContext(); UserQuizQuestionAnswer uqqa = db.UserQuizQuestionAnswers.First(u => u.userId == userId && u.questionId == questionId); return(getAnswerById(uqqa.answerId)); }
public ActionResult SubmitQuiz(UserAnswer[] answers) { UserViewModel vmUser = session.getSessionUser(); if (vmUser == null) { if (!val.getUserCredentials(Request)) { return(RedirectToAction("Login", "Home")); } vmUser = session.getSessionUser(); } Queries query = new Queries(); User user = query.getUserBySam(vmUser.modelToUser(session.getSessionUser()).SAMAccountName); List <UserQuizQuestionAnswer> uqqas = new List <UserQuizQuestionAnswer>(); foreach (UserAnswer answer in answers) { UserQuizQuestionAnswer uqqa = new UserQuizQuestionAnswer(); uqqa.quizId = answer.quizId; uqqa.questionId = answer.questionId; uqqa.answerId = answer.answerId; uqqa.userId = user.id; uqqa.text = answer.answerText; uqqa.isChecked = false; uqqa.isApproved = false; uqqas.Add(uqqa); } uqqas = GradeSubmittedQuiz(GetQuizById(answers[0].quizId), uqqas); List <UserQuizQuestionAnswer> addedUqqas = new List <UserQuizQuestionAnswer>(); addedUqqas = query.submitQuiz(uqqas); if (addedUqqas.Count > 0) { return(Json("Quiz Completed", JsonRequestBehavior.AllowGet)); } return(Json("Failed to submit quiz", JsonRequestBehavior.AllowGet)); }