public void AddQuiz(Quizze q) { List <Quizze> temp = Quizzes.ToList(); temp.Add(q); Quizzes = temp; }
public ActionResult TakeQuiz(int QuizID) { Quizze Quiz = db.Quizzes.Where(q => q.QuizID == QuizID).FirstOrDefault(); if (Quiz == null) { RedirectToAction("Index", "Home"); } int classID = Quiz.ClassID; if (test(classID) != null) { return(test(classID)); } var idid = User.Identity.GetUserId(); User user = db.Users.Where(a => a.IdentityID == idid).FirstOrDefault(); StudentQuizze HasTaken = db.StudentQuizzes.Where(q => q.QuizID == Quiz.QuizID && q.UserID == user.UsersID).FirstOrDefault(); if (HasTaken != null) { return(RedirectToAction("Index", "Class", new { classId = classID })); } StudentVM student = getSVM(classID); student.StudentQuiz = new StudentQuizze(); student.StudentQuiz.QuizID = QuizID; student.Quiz = Quiz; student.questionList = db.QuizQuestions.Where(q => q.QuizID == QuizID).ToList(); student.answerList = db.MultChoiceAnswers.Where(q => q.QuizQuestion.QuizID == QuizID).ToList(); student.StudentAnswers = new List <StudentAnswer>(); return(View("TakeQuiz", "_StudentLayout", student)); }
public IHttpActionResult GetQuizById(string quizId) { // Check we have an ID and make a GUID if (String.IsNullOrEmpty(quizId)) { return(NotFound()); } Guid QuizGuid = new Guid(quizId); // If we do then lets find the quiz Quizze Quiz = WmData.Quizzes.FirstOrDefault(q => q.QuizId == QuizGuid); // If we find a quiz then lets return it if (Quiz != null) { return(Ok(Quiz)); } else { return(NotFound()); } }
/// <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 IHttpActionResult AddQuiz([FromBody] NewQuiz newQuiz) { if (newQuiz is null) { return(NotFound()); } // Generate Quiz var NewQuiz = new Quizze(); NewQuiz.QuizId = Guid.NewGuid(); NewQuiz.SessionId = new Guid(newQuiz.SessionId); NewQuiz.QuizTitle = newQuiz.QuizTitle; NewQuiz.QuizInstructions = newQuiz.QuizInstructions; NewQuiz.QuizPassMark = newQuiz.QuizPassMark; NewQuiz.QuizTest = newQuiz.QuizTest; // Add to database WmData.Quizzes.Add(NewQuiz); WmData.SaveChanges(); // Return the new QuizId return(Ok(NewQuiz.QuizId)); }
public ActionResult Quiz(int quizId) { Quizze quizToDisplay = _entitites.Quizzes.Find(quizId); return(View(quizToDisplay)); }
public void RemoveQuiz(Quizze q) { }
public QuizViewModel(Quizze q, KwisspelEntities context) { _context = context; _quizze = q; }
public QuizViewModel(KwisspelEntities context) { _context = context; _quizze = new Quizze(); }
public IHttpActionResult AddQuizResult(string quizId, string username, int score) { // Check we have all the parameters we need if (String.IsNullOrEmpty(quizId) || String.IsNullOrEmpty(username)) { return(NotFound()); } // We do, cool, lets find the user User UserDb = WmData.Users.FirstOrDefault(u => u.Username == username); // Right now we've got the user, lets add the result QuizResult Result = new QuizResult(); Guid QuizId = new Guid(quizId); if (UserDb != null) { // Set result values Result.QuizId = QuizId; Result.QuizResultId = Guid.NewGuid(); Result.QuizResultScore = score; Result.UserId = UserDb.UserId; // Check to see if the user passed Quizze Quiz = WmData.Quizzes.FirstOrDefault(q => q.QuizId == QuizId); if (Quiz.QuizPassMark >= Result.QuizResultScore) { Result.QuizResultPass = "******"; } else { Result.QuizResultPass = "******"; } // Check to see if we already have a result for this quiz and user List <QuizResult> ExistingResults = WmData.QuizResults.Where(q => q.QuizId == QuizId).ToList(); QuizResult ExisitingResult = ExistingResults.FirstOrDefault(u => u.UserId == UserDb.UserId); if (ExisitingResult == null) { // As it's the first run through, they can have a badge, yey! var BadgeCrtl = new BadgeController(); bool BadgeAwarded = BadgeCrtl.AwardBadgeByType(Quiz.QuizId, "challenge", UserDb.UserId); if (!BadgeAwarded) { return(NotFound()); } // Add Result WmData.QuizResults.Add(Result); } else { // Update Result only (no badge for these guys) ExisitingResult.QuizResultScore = score; ExisitingResult.QuizResultPass = Result.QuizResultPass; } WmData.SaveChanges(); } else { return(NotFound()); } // Added? Right, lets tell the app return(Ok("Result Added to Trailblazer")); }
public void RemoveQuiz(Quizze q) { db.Quizzes.Remove(q); }
public void AddQuiz(Quizze q) { db.Quizzes.Add(q); }