Пример #1
0
        public IActionResult View(string formId, Guid answersSetId)
        {
            // Try to get the quiz form
            Form form = _formsRepository.GetById(formId);

            if (form == null)
            {
                return(NotFound());
            }

            // Try to get the answers set
            FormAnswersSet answerSet = _answersRepository.Get(formId, answersSetId);

            if (answerSet == null)
            {
                return(NotFound());
            }

            // Try to get the existing scores
            Dictionary <string, int> scores = _scoresRepository.GetScore(formId, answersSetId);

            // Combine the data into a extended form answers model
            ExtendedFormAnswersSet model = AnswerChecking.ConstructExtendedFormAnswersSet(answerSet, form, scores);

            return(View(model));
        }
Пример #2
0
        public IActionResult AutoCheck(string formId)
        {
            // Try to get the quiz form
            Form form = _formsRepository.GetById(formId);

            if (form == null)
            {
                return(NotFound());
            }

            // Loop through the answer sets
            foreach (FormAnswersSet answerSet in _answersRepository.GetAll(formId))
            {
                // Get the stored scores
                Dictionary <string, int> scores = _scoresRepository.GetScore(formId, answerSet.Id);

                // Combine the data into a extended form answers model
                ExtendedFormAnswersSet model = AnswerChecking.ConstructExtendedFormAnswersSet(answerSet, form, scores);

                // Save the score if no manual checking is required
                if (model.ManualCheckingRequiredCount == 0)
                {
                    // Extract the scores
                    scores = model.Answers.ToDictionary(x => x.QuestionId, x => x.AssignedPoints.Value);

                    // Update the score
                    _scoresRepository.UpdateScore(formId, answerSet.Id, scores);
                }
            }

            // Redirect to the overview
            return(RedirectToAction("Index", new { formId }));
        }