コード例 #1
0
        public IActionResult Details(int questionId)
        {
            var question = _questionDao.GetAll().FirstOrDefault(q => q.Id == questionId);

            if (question != null)
            {
                List <CreateOrUpdateQuestionAnswerViewModel> answers = null;
                if (question.Type.Name == "QCM")
                {
                    var answerDtos = _answerDao.GetAll().Where(r => r.QuestionId == questionId);
                    answers = answerDtos.Select(r => new CreateOrUpdateQuestionAnswerViewModel
                    {
                        Id              = r.Id,
                        QuestionId      = r.QuestionId,
                        AnswerContent   = r.Content,
                        QuestionContent = question.Content
                    }).ToList();
                }


                var model = new ViewModels.QuestionViewModel()
                {
                    Id                 = question.Id,
                    Content            = question.Content,
                    DifficultyLevel    = question.Difficulty.DifficultyLevel,
                    CategoryName       = question.Category.Name,
                    QuestionTypeName   = question.Type.Name,
                    QuestionAnswerList = answers,
                    TypeName           = question.Type.Name
                };

                return(View(model));
            }
            return(RedirectToAction("List"));
        }
コード例 #2
0
        public IActionResult ConfirmDeleteOrNo(int questionId)
        {
            var question = _questionDao.GetAll().FirstOrDefault(q => q.Id == questionId);

            if (question != null)
            {
                var model = new ViewModels.QuestionViewModel()
                {
                    Id               = question.Id,
                    Content          = question.Content,
                    DifficultyLevel  = question.Difficulty.DifficultyLevel,
                    CategoryName     = question.Category.Name,
                    QuestionTypeName = question.Type.Name,
                };
                return(View("ConfirmDeleteOrNo", model));
            }

            return(RedirectToAction("DeleteError"));
        }