Esempio n. 1
0
        public async Task <IActionResult> AddNewQuestion(QuestionInputViewModel model)
        {
            var quizId     = this.HttpContext.Session.GetString(Constants.QuizSessionId);
            var questionId = await this.questionsService.CreateQuestionAsync(quizId, model.Text);

            this.HttpContext.Session.SetString(Constants.CurrentQuestionId, questionId);
            return(this.RedirectToAction("AnswerInput", "Answers"));
        }
        // GET: Questions/Create
        public IActionResult Create()
        {
            // Get the list of topics for select topic option
            ViewData["TopicID"] = new SelectList(Topics, "TopicID", "Description");

            // Set the Creator of the question to the current user
            QuestionInputViewModel questionVM = new QuestionInputViewModel
            {
                Creator = _currentUser
            };

            return(View(questionVM));
        }
        public int SubmitQuestion(QuestionInputViewModel viewModel)
        {
            var question = new Question
            {
                Title            = viewModel.Title,
                QuestionUrl      = viewModel.QuestionUrl,
                Notes            = viewModel.Notes,
                QuestionUploaded = DateTime.UtcNow,
                QuestionType     = viewModel.QuestionType
            };

            this.questionRepository.Insert(question);
            this.questionRepository.SaveChanges();

            return(question.Id);
        }
        public IActionResult Create(QuestionInputViewModel questionVM)
        {
            ViewData["TopicID"] = new SelectList(Topics, "TopicID", "Description", questionVM.TopicID);

            // Set the text for choices to a list of strings
            List <string> choicesText = new List <string>()
            {
                { questionVM.Choice1 },
                { questionVM.Choice2 },
                { questionVM.Choice3 }
            };

            // A container for the choice objects
            List <Choice> choices = new List <Choice>();

            foreach (var item in choicesText)
            {
                // Create the choice objects
                Choice choice = new Choice
                {
                    Text = item
                };
                choices.Add(choice);
            }

            // Create a new entity object and set the entities properties to the values in the ViewModel
            Question question = new Question
            {
                Creator = questionVM.Creator,
                TopicID = questionVM.TopicID,
                Body    = questionVM.Body,
                Answer  = questionVM.Answer,
                Choices = choices
            };

            if (ModelState.IsValid)
            {
                _questionData.Add(question);

                return(RedirectToAction("Index", "UserAccount"));
            }

            return(View(questionVM));
        }
 public void SubmitQuestion([FromBody] QuestionInputViewModel viewModel) => this.questionService.SubmitQuestion(viewModel);