示例#1
0
        public async Task <IActionResult> CreateQuestion(NewQuestionInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            var newQuestion = await this.surveysService.CreateQuestionAsync(inputModel);

            return(this.RedirectToAction(nameof(this.SurveyIndex)));
        }
示例#2
0
        public async Task <string> CreateQuestionAsync(NewQuestionInputModel inputModel)
        {
            var newQuestion = new Question
            {
                Number   = inputModel.Number,
                SurveyId = inputModel.SurveyId,
                Text     = inputModel.Text,
            };

            await this.questionsRepository.AddAsync(newQuestion);

            await this.questionsRepository.SaveChangesAsync();

            return(newQuestion.Id);
        }
示例#3
0
        public async Task <IActionResult> EditQuestion(NewQuestionInputModel inputModel)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.View(inputModel));
            }

            try
            {
                await this.surveysService.EditQuestionAsync(inputModel.Id, inputModel.Text);
            }
            catch (Exception)
            {
                return(this.CustomCommonError());
            }

            return(this.RedirectToAction(nameof(this.SurveyIndex)));
        }
        public async Task CreateQuestionAsync_ShouldCreateNewQuestionProperly()
        {
            AutoMapperConfig.RegisterMappings(typeof(QuestionViewModel).Assembly);
            var surveyId   = "1";
            var inputModel = new NewQuestionInputModel
            {
                Text     = "20",
                SurveyId = surveyId,
            };

            var questionId = await this.service.CreateQuestionAsync(inputModel);

            var allQuestion = await this.service.GetAllQuestionsBySurveyIdAsync <QuestionViewModel>(surveyId);

            var expectedQuestionsCount = 4;

            Assert.Equal(expectedQuestionsCount, allQuestion.Count());
            Assert.NotNull(questionId);
        }
示例#5
0
        // =============================================== QUESTION ===============================================
        public async Task <IActionResult> CreateQuestion(string id)
        {
            var surveyTitle = await this.surveysService.GetSurveyTitleByIdAsync(id);

            if (surveyTitle == null)
            {
                return(this.CustomNotFound());
            }

            var questionNumber = await this.surveysService.GetQuestionNumberBySurveyIdAsync(id);

            var nextQuestionNumber = questionNumber + 1;

            var model = new NewQuestionInputModel
            {
                SurveyId    = id,
                SurveyTitle = surveyTitle,
                Number      = nextQuestionNumber,
            };

            return(this.View(model));
        }
示例#6
0
        public async Task <IActionResult> EditQuestion(string questionId)
        {
            if (questionId == null)
            {
                return(this.CustomNotFound());
            }

            var inputModel = new NewQuestionInputModel();

            try
            {
                var existingQuestion = await this.surveysService.GetQuestionByIdAsync <QuestionViewModel>(questionId);

                inputModel.Id     = existingQuestion.Id;
                inputModel.Text   = existingQuestion.Text;
                inputModel.Number = existingQuestion.Number;
            }
            catch (Exception)
            {
                return(this.CustomCommonError());
            }

            return(this.View(inputModel));
        }