Example #1
0
 public static QuizAttempt AddQuizAttempt(QuizAttempt quizAttempt)
 {
     using (QuizBuilderDb db = new QuizBuilderDb())
     {
         QuizAttempt toAdd = quizAttempt;
         db.QuizAttempts.Add(toAdd);
         db.SaveChanges();
         return toAdd;
     }
 }
Example #2
0
 public ActionResult NewQuiz(int quizId)
 {
     QuizAttempt newAttempt = new QuizAttempt { UserID = UserService.FindByName(User.Identity.Name).UserID, QuizID = quizId, QuizDate = DateTime.Now };
     newAttempt = QuizService.AddQuizAttempt(newAttempt);
     int[] quizScenarioIds = ScenarioService.GetScenarios().Where(s => s.QuizID == quizId).Select(s => s.ScenarioID).ToArray();
     Question[] questionArray = QuestionService.GetQuestions().Where(q => quizScenarioIds.Contains(q.ScenarioID)).ToArray();
     ViewData.Add("QuestionArray", questionArray);
     ViewData.Add("SelectedQuestion", questionArray[0].QuestionID);
     return View("TakeQuiz", newAttempt);
 }
Example #3
0
 public static QuizAttempt UpdateQuizAttempt(QuizAttempt updatedAttempt)
 {
     using (QuizBuilderDb db = new QuizBuilderDb())
     {
         QuizAttempt currentAttempt = db.QuizAttempts.Find(updatedAttempt.QuizAttemptID);
         if (currentAttempt != null)
         {
             currentAttempt.QuizDate = updatedAttempt.QuizDate;
             currentAttempt.Score = updatedAttempt.Score;
             db.SaveChanges();
             return currentAttempt;
         }
         else
             return currentAttempt;
     }
 }