示例#1
0
        public IActionResult CreateQuestion([FromBody] QuestionForCreationDto question)
        {
            if (question == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(new UnprocessableEntityObjectResultTunsBad(ModelState));
            }

            var questionEntity = Mapper.Map <Question>(question);

            _quizRepository.AddQuestion(questionEntity);

            if (!_quizRepository.Save())
            {
                throw new Exception("Creating an question failed on save.");
            }

            var questionToReturn = Mapper.Map <QuestionDto>(questionEntity);

            return(CreatedAtRoute("CreateQuestion",
                                  new { id = questionToReturn.Id },
                                  questionToReturn));
        }
示例#2
0
 public ActionResult Create(Question newQuestion, FormCollection collection)
 {
     try
     {
         _questionRepo.AddQuestion(newQuestion);
         return(RedirectToAction("Index"));
     }
     catch
     {
         return(View());
     }
 }
        public IActionResult CreateQuestionCollection([FromBody] IEnumerable <QuestionForCreationDto> questionCollection)
        {
            if (questionCollection == null)
            {
                return(BadRequest());
            }

            var questionEntities = Mapper.Map <IEnumerable <Question> >(questionCollection);

            foreach (var question in questionEntities)
            {
                _quizRepository.AddQuestion(question);
            }

            if (!_quizRepository.Save())
            {
                throw new Exception("Creating an questions collection failed on save.");
            }

            return(Ok());
        }
示例#4
0
        public async Task <Quiz> AddQuestion(ObjectId QuizId, string Question, string Answer)
        {
            var quiz = await _quizRepository.AddQuestion(QuizId, Question, Answer);

            return(quiz);
        }