コード例 #1
0
        public IActionResult Create([FromQuery] int surveyId)
        {
            var viewModel = new QuestionBindingModel()
            {
                SurveyId = surveyId
            };

            return(View(viewModel));
        }
コード例 #2
0
 public IActionResult AddQuestion(QuestionBindingModel bindingModel)
 {
     if (ModelState.IsValid)
     {
         var user = userMgr.FindByNameAsync(User.Identity.Name).Result;
         discussService.AddQuestion(bindingModel, user);
         return(RedirectToAction(Actions.All, Paths.Discussions));
     }
     return(View(bindingModel));
 }
コード例 #3
0
        public async Task <IActionResult> Edit([FromForm] QuestionBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var questionModel = model.ToServiceModel();
                await _questionService.EditQuestionAsync(questionModel);

                return(RedirectToAction("Edit", "Survey", new { questionModel.SurveyId }));
            }

            return(View(model));
        }
コード例 #4
0
        public QuestionBindingModel GetTestQuestionBM(Category category)
        {
            var model = new QuestionBindingModel()
            {
                Title    = "TestQuestion",
                Content  = "Just a test content",
                Tags     = "web nice",
                Category = category
            };

            return(model);
        }
コード例 #5
0
        public QuestionBindingModel GetTestQuestionBM()
        {
            var model = new QuestionBindingModel()
            {
                Title    = "TestQuestion",
                Content  = "Just a test content",
                Tags     = "web nice",
                Category = Category.WebDevelopment
            };

            return(model);
        }
コード例 #6
0
        //Tested
        public Question AddQuestion(QuestionBindingModel model, CustomUser publisher)
        {
            var question = new Question(model.Title, model.Content, model.Category, publisher);

            this.context.Questions.Add(question);
            this.context.SaveChanges();
            var tags = GenerateTagEntities(model.Tags, question);

            question.Tags = tags;
            this.context.SaveChanges();
            return(question);
        }
コード例 #7
0
        public IHttpActionResult CreateQuestion([FromBody] QuestionBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            QuestionDTO newQuestion = _mapper.Map <QuestionDTO>(model);

            this._questionService.Add(newQuestion);

            return(Ok());
        }
コード例 #8
0
        public async Task <ActionResult <Question> > PostQuestion(QuestionBindingModel question)
        {
            Question newquestion = new Question
            {
                Title         = question.Title,
                Content       = question.Content,
                CreatedUserID = question.CreatedUserID
            };

            _context.Questions.Add(newquestion);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetQuestion", new { id = newquestion.QuestionId }, question));
        }
コード例 #9
0
        public async Task <IActionResult> Create([FromForm] QuestionBindingModel model)
        {
            if (ModelState.IsValid)
            {
                var questionModel = model.ToServiceModel();
                await _questionService.CreateQuestionAsync(questionModel);

                int questionId = questionModel.Id;
                int surveyId   = questionModel.SurveyId;

                return(RedirectToAction($"Create", "Option", new { surveyId, questionId }));
            }

            return(View(model));
        }
コード例 #10
0
        public void WithValidModelReturnsQuestionViewModel()
        {
            var question = new QuestionBindingModel()
            {
                Content = "Test question"
            };

            var model = new JoinEventViewModel()
            {
                EventId = 1, Question = question
            };

            var result = this.service.GetQuestionModel(model);

            Assert.AreEqual(typeof(QuestionViewModel), result.GetType());
        }
コード例 #11
0
        public async Task <ActionResult <Question> > PostQuestion(String token, QuestionBindingModel question)
        {
            if (token == null)
            {
                return(Unauthorized());
            }

            Question newquestion = new Question
            {
                Title         = question.Title,
                Content       = question.Content,
                CreatedUserID = question.CreatedUserID,
                Tag           = question.Tag
            };

            _context.Questions.Add(newquestion);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetQuestion", new { id = newquestion.QuestionId }, question));
        }
コード例 #12
0
        public IHttpActionResult UpdateQuestion(int id, [FromBody] QuestionBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            QuestionDTO questionToUpdate = this._questionService.GetById(id);

            if (questionToUpdate == null)
            {
                return(Content(HttpStatusCode.NotFound,
                               $"Test category with id={id} does not exist."));
            }

            QuestionDTO updatedQuestion = _mapper.Map <QuestionDTO>(model);

            this._questionService.Update(updatedQuestion);

            return(Ok());
        }
コード例 #13
0
        public async Task <IActionResult> PutQuestion(Guid id, QuestionBindingModel updated_question)
        {
            if (id == null)
            {
                return(BadRequest());
            }

            var question = await _context.Questions.FindAsync(id);

            if (question == null)
            {
                return(NotFound());
            }

            question.Title   = updated_question.Title;
            question.Content = updated_question.Content;

            _context.Entry(question).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!QuestionExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }