public QuizVersion FindQuizVersionFromUsersAnswer(string courseId, Guid slideId, string userId) { var firstUserAnswer = db.UserQuizzes.FirstOrDefault(x => x.UserId == userId && x.SlideId == slideId && !x.isDropped); if (firstUserAnswer == null) { return(null); } /* If we know version which user has answered*/ if (firstUserAnswer.QuizVersion != null) { return(firstUserAnswer.QuizVersion); } /* If user's version is null, show first created version for this slide ever */ var quizzesRepo = new QuizzesRepo(db); return(quizzesRepo.GetFirstQuizVersion(courseId, slideId)); }
public async Task <UserQuiz> AddUserQuiz(string courseId, bool isRightAnswer, string itemId, string quizId, Guid slideId, string text, string userId, DateTime time, int quizBlockScore, int quizBlockMaxScore) { var quizzesRepo = new QuizzesRepo(db); var currentQuizVersion = quizzesRepo.GetLastQuizVersion(courseId, slideId); var userQuiz = new UserQuiz { CourseId = courseId, SlideId = slideId, QuizVersionId = currentQuizVersion.Id, IsRightAnswer = isRightAnswer, ItemId = itemId, QuizId = quizId, Text = text, Timestamp = time, UserId = userId, QuizBlockScore = quizBlockScore, QuizBlockMaxScore = quizBlockMaxScore }; db.UserQuizzes.Add(userQuiz); await db.SaveChangesAsync(); return(userQuiz); }