Esempio n. 1
0
        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)));
        }
Esempio n. 2
0
        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));
        }
Esempio n. 4
0
        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));
        }
Esempio n. 5
0
        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);
        }
Esempio n. 6
0
 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);
 }
Esempio n. 7
0
        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));
        }
Esempio n. 9
0
 public ActionResult <Question> CreateQuestion(CreateQuestionDto createQuestionDto)
 {
     return(questionService.CreateQuestion(createQuestionDto));
 }