public async Task <ActionResult> CreateQuestion([FromBody] CreateQuestionDto question) { if (question == null) { return(BadRequest()); } if (!ModelState.IsValid) { return(new UnprocessableEntityObjectResult(ModelState)); } if (await _repository.isQuestionTextExist(question.QuestionText)) { return(BadRequest("The question text inputed already exist")); } var questionToAdd = _mapper.Map <Question>(question); _repository.Add(questionToAdd); if (!await _repository.SaveChangesAsync()) { throw new Exception("An error occured while trying to save question"); } return(CreatedAtRoute("GetQuestion", new { questionId = questionToAdd.Id }, _mapper.Map <QuestionDto>(questionToAdd))); }
public IActionResult CreateQuestion([FromBody] CreateQuestionDto question) { var newQuestion = new QuestionDto { Id = Guid.NewGuid() }; return(StatusCode(200, newQuestion)); }
public async Task <ActionResult <Question> > Post(CreateQuestionDto question) { if (question == null) { return(BadRequest()); } var NewQuestion = _mapper.Map <CreateQuestionDto, Question>(question); db.Questions.Add(NewQuestion); await db.SaveChangesAsync(); return(Ok(question)); }
public async Task <ServiceResponse <GetQuestionDto> > CreateQuestion(CreateQuestionDto question, int pollId) { var dalQuestion = _mapper.Map <Question>(question); dalQuestion.Poll = pollId; await _context.Questions.AddAsync(dalQuestion); await _context.SaveChangesAsync(); var getQuestionDto = _mapper.Map <GetQuestionDto>(dalQuestion); return(new ServiceResponse <GetQuestionDto>().Success(getQuestionDto, QuestionCreatedStr)); }
public async Task <Question> CreateQuestion(CreateQuestionDto input) { var question = new Question { Title = input.Title, Description = input.Description, EntityType = input.EntityType, EntityId = input.EntityId, UserId = input.UserId }; await _questionRepository.AddAsync(question); return(question); }
public Question CreateQuestion(CreateQuestionDto createQuestionDto) { if (_context.Quizzes .Any(q => q.Id == createQuestionDto.QuizId)) { var question = new Question() { Text = createQuestionDto.Text, SecondsToAnswer = createQuestionDto.SecondsToAnswer, Points = createQuestionDto.Points, QuizId = createQuestionDto.QuizId, Position = createQuestionDto.Position }; _context.Questions.Add(question); _context.SaveChanges(); foreach (CreateAnswerDto createAnswerDto in createQuestionDto.Answers) { createAnswerDto.QuestionId = question.Id; answerService.CreateAnswer(createAnswerDto); } return(GetQuestion(question.Id)); } return(null); }
public async Task <IActionResult> CreateQuestion(CreateQuestionDto input) { var result = await _questionAppService.CreateQuestion(input); return(Ok(result)); }
public async Task <ActionResult <CreatedQuestionDto> > CreateQuestion(CreateQuestionDto createQuestionDto) { var result = await _mediator.Send(new CreateQuestionCommand(createQuestionDto)); return(Ok(result)); }
public ActionResult <Question> CreateQuestion(CreateQuestionDto createQuestionDto) { return(questionService.CreateQuestion(createQuestionDto)); }