public IActionResult RegisterQuiz(string userEmail, int quizid) { var user = _context.User.FirstOrDefault(u => u.UserEmail == userEmail); var quiz = _context.Quiz.FirstOrDefault(q => q.QuizId == quizid); var userQuiz = new UserQuiz(); userQuiz.QuizId = quiz.QuizId; userQuiz.UserId = user.UserId; userQuiz.UserRegisterDate = DateTime.Now; userQuiz.CreatedBy = "Admin"; userQuiz.ModifiedBy = "Admin"; userQuiz.CreatedDateTime = DateTime.Now; userQuiz.ModifiedDateTime = DateTime.Now; _context.UserQuiz.Add(userQuiz); _context.SaveChanges(); var quizes = GetQuiz(userEmail); return(Ok(quizes.FirstOrDefault())); }
public IActionResult SubmitResponse(int userid, int quizid, int questionid, int responseid) { var userQuiz = _context.UserQuiz.FirstOrDefault(uq => uq.UserId == userid && uq.QuizId == quizid); if (userQuiz != null) { var quizResponse = new UserQuizResponse(); quizResponse.IsCorrect = true; quizResponse.UserQuizId = userQuiz.UserQuizId; quizResponse.IsDeleted = false; quizResponse.QuestionId = questionid; quizResponse.CreatedBy = "Admin"; quizResponse.ModifiedBy = "Admin"; quizResponse.CreatedDateTime = DateTime.Now; quizResponse.ModifiedDateTime = DateTime.Now; _context.Add(quizResponse); _context.SaveChanges(); } return(Ok()); }