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)); }
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()); }
public async Task <Quiz> AddQuestion(ObjectId QuizId, string Question, string Answer) { var quiz = await _quizRepository.AddQuestion(QuizId, Question, Answer); return(quiz); }