Exemplo n.º 1
0
        public IActionResult Quiz(ViewTrainingModel model, IFormCollection form)
        {
            int correctAnswers = 0;
            var training       = _trainingService.GetTrainingById(model.Training.TrainingId);

            List <int> questions = (from object key in form.Keys where key.ToString().StartsWith("question_") select int.Parse(key.ToString().Replace("question_", ""))).ToList();

            foreach (var questionId in questions)
            {
                var answerForQuestion = form["question_" + questionId].ToString();

                if (answerForQuestion != null)
                {
                    var question = training.Questions.FirstOrDefault(x => x.TrainingQuestionId == questionId);
                    if (question != null)
                    {
                        var answer = question.Answers.FirstOrDefault(x => x.TrainingQuestionAnswerId == int.Parse(answerForQuestion));
                        if (answer != null && answer.Correct)
                        {
                            correctAnswers++;
                        }
                    }
                }
            }

            _trainingService.RecordTrainingQuizResult(training.TrainingId, UserId, correctAnswers);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
        public IActionResult ResetUserTraining(int trainingId, string userId)
        {
            var model = new ViewTrainingModel();

            model.Training = _trainingService.GetTrainingById(trainingId);

            if (model.Training.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            _trainingService.ResetUser(trainingId, userId);

            return(RedirectToAction("Report", new { trainingId = model.Training.TrainingId }));
        }
Exemplo n.º 3
0
        public IActionResult DeleteTraining(int trainingId)
        {
            var model = new ViewTrainingModel();

            model.Training = _trainingService.GetTrainingById(trainingId);

            if (model.Training.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            _trainingService.DeleteTraining(trainingId);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 4
0
        public IActionResult Quiz(int trainingId)
        {
            var model = new ViewTrainingModel();

            model.Training = _trainingService.GetTrainingById(trainingId);

            if (model.Training.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            _trainingService.SetTrainingAsViewed(trainingId, UserId);

            return(View(model));
        }
Exemplo n.º 5
0
        public async Task <IActionResult> DeleteTraining(int trainingId)
        {
            var model = new ViewTrainingModel();

            model.Training = await _trainingService.GetTrainingByIdAsync(trainingId);

            if (model.Training.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            await _trainingService.DeleteTrainingAsync(trainingId);

            return(RedirectToAction("Index"));
        }
Exemplo n.º 6
0
        public async Task <IActionResult> Quiz(int trainingId, CancellationToken cancellationToken)
        {
            var model = new ViewTrainingModel();

            model.Training = await _trainingService.GetTrainingByIdAsync(trainingId);

            if (model.Training.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            await _trainingService.SetTrainingAsViewedAsync(trainingId, UserId, cancellationToken);

            return(View(model));
        }
Exemplo n.º 7
0
        public IActionResult View(int trainingId)
        {
            var model = new ViewTrainingModel();

            model.Training        = _trainingService.GetTrainingById(trainingId);
            model.CreatorUserName = UserHelper.GetFullNameForUser(model.Training.CreatedByUserId);

            if (model.Training.DepartmentId != DepartmentId)
            {
                Unauthorized();
            }

            _trainingService.SetTrainingAsViewed(trainingId, UserId);

            return(View(model));
        }