示例#1
0
        // To protect from overposting attacks, see https://aka.ms/RazorPagesCRUD
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            if (SurveyId != null)
            {
                await _databaseLogic.CreateQuestion(Question, SurveyId);
            }
            else
            {
                await _databaseLogic.CreateQuestion(Question);
            }

            if (Question.QuestionType != QuestionType.Text && NumberOfAnswers > 0)
            {
                return(RedirectToPage("/AnswerPages/CreateMultipleAnswers",
                                      new
                {
                    numberOfAnswers = NumberOfAnswers,
                    questionId = Question.Id
                }));
            }
            return(RedirectToPage(
                       "/QuestionPages/Details",
                       new
            {
                id = Question.Id
            }));
        }
        // To protect from overposting attacks, enable the specific properties you want to bind to.
        // For more details, see https://aka.ms/RazorPagesCRUD.
        public async Task <IActionResult> OnPostAsync()
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            Question = await _databaseLogic.CreateQuestion(Question, Survey.Id);

            NumberOfQuestionsLeft -= 1;

            if (Question.QuestionType == QuestionType.Text || NumberOfAnswers < 1)
            {
                if (NumberOfQuestionsLeft > 0)
                {
                    return(RedirectToPage(
                               new
                    {
                        numberOfQuestionsLeft = NumberOfQuestionsLeft,
                        surveyId = Survey.Id
                    }));
                }
                return(RedirectToPage("/SurveyPages/CompleteSurvey", new { surveyId = Survey.Id }));
            }
            else
            {
                return(RedirectToPage("/AnswerPages/CreateMultipleAnswers",
                                      new
                {
                    numberOfQuestionsLeft = NumberOfQuestionsLeft,
                    numberOfAnswers = NumberOfAnswers,
                    questionId = Question.Id
                }));
            }
        }