Example #1
0
        public ActionResult Test(int categoryId)
        {
            List <Question> questions = questionService.GetQuestionsByCategory(categoryId, 10).ToList();

            ViewBag.jsonQuestions = Newtonsoft.Json.JsonConvert.SerializeObject(
                questions.Select(q => new { id = q.Id, text = q.QuestionString, answer = string.Empty }).ToList());

            Attempt attempt = new Attempt()
            {
                CategoryId = categoryId,
                UserId     = CurrentUser.Id,
            };

            ViewBag.attemptId = attemptService.CreateAttempt(attempt);
            return(View());
        }
        public int Start([FromBody] PINRequest value)
        {
            PIN pin = _pinService.FindByCode(value.code);

            if (pin != null)
            {
                var user    = _userManager.GetUserId(User);
                var attempt = new Attempt {
                    PINID = pin.Id, UserId = user, StartDate = DateTime.Now
                };
                _attemptService.CreateAttempt(attempt);
                HttpContext.Session.SetInt32("attempt", attempt.Id);
                var questions = _questionService.GetQuestionsByQuizID(pin.QuizID);
                foreach (var question in questions)
                {
                    var result = new Result {
                        QuestionID = question.Id, AttemptID = attempt.Id, Response = false
                    };
                    _resultService.CreateResult(result);
                }
                return(pin.QuizID);
            }
            return(0);
        }