public async Task <CreatedQuestionDto> Handle(CreateQuestionCommand request, CancellationToken cancellationToken)
        {
            var question = new Question
            {
                QuestionText = request.Dto.QuestionText
            };

            _dbContext.Add(question);
            await _dbContext.SaveChangesAsync();

            return(_mapper.Map <CreatedQuestionDto>(question));
        }
Exemplo n.º 2
0
        public async Task <CreatedChoiceDto> Handle(CreateChoiceCommand request, CancellationToken cancellationToken)
        {
            var choice = new Choice
            {
                ChoiceText = request.Dto.ChoiceText,
                IsCorrect  = request.Dto.IsCorrect,
                QuestionId = request.Dto.QuestionId
            };

            _dbContext.Add(choice);
            await _dbContext.SaveChangesAsync();

            var createdChoiceDto = new CreatedChoiceDto
            {
                ChoiceId   = choice.ChoiceId,
                ChoiceText = choice.ChoiceText,
                IsCorrect  = choice.IsCorrect,
                QuestionId = choice.QuestionId
            };

            return(createdChoiceDto);
        }