Beispiel #1
0
        public async Task <IActionResult> CreateAnswer(AnswerModel model)
        {
            if (ModelState.IsValid && await _questionManager.IsQuestionExistsAsync(model.QuestionId))
            {
                var domainAnswer = _mapper.Map <DomainAnswer>(model);
                int answersCount = await _answersManager.GetAnswerCountByQuestionIdAsync(model.QuestionId);

                if (model.QuestionType == QuestionTypes.Text && answersCount >= 1)
                {
                    return(BadRequest());
                }

                await _answersManager.CreateAnswerAsync(domainAnswer);

                DomainTest test = await _testManager.GetTestByIdAsync(model.TestId);

                return(RedirectToAction("EditQuestion", "Test",
                                        new { @TopicId = test.TopicId, @TestId = model.TestId, @QuestionId = model.QuestionId, @QuestionType = model.QuestionType }));
            }

            ModelState.AddModelError("", "Invalid Question information");

            return(View(model));
        }