Exemplo n.º 1
0
 public async Task <List <QuestionDto> > Handle(GetQuestionsQuery request, CancellationToken cancellationToken)
 {
     return(await _context.Questions
            .Where(x => x.UserId == request.UserId)
            .Select(QuestionDto.Projection)
            .ToListAsync());
 }
Exemplo n.º 2
0
        public async Task <QueryResult <Question> > GetQuestions(GetQuestionsQuery query,
                                                                 CancellationToken cancellationToken)
        {
            var queryable = _context
                            .Questions
                            .AsNoTracking()
                            .Where(x => x.QuestionnaireId == query.QuestionnaireId);

            var totalCount = await queryable.CountAsync(cancellationToken);

            var questions = await queryable
                            .Include(x => x.Texts
                                     .Where(t => t.Locale == query.Locale))
                            .Include(x => x.AnswerOptions
                                     .OrderBy(i => i.OrderNumber))
                            .ThenInclude(x => x.Texts
                                         .Where(t => t.Locale == query.Locale))
                            .OrderBy(x => x.Subject.OrderNumber)
                            .ThenBy(x => x.OrderNumber)
                            .Take(query.Limit)
                            .Skip(query.Offset)
                            .ToArrayAsync(cancellationToken);

            return(new QueryResult <Question>(totalCount, query.Limit, query.Offset, questions));
        }
        public Task <List <Question> > Handle(GetQuestionsQuery request, CancellationToken cancellationToken)
        {
            var questions = _questionsRepository.GetQuestions(request.Tag);

            // return questions;
            return(Task.FromResult(questions));
        }
        public async Task <List <QuestionDto> > Handle(GetQuestionsQuery request, CancellationToken cancellationToken)
        {
            var connection = this._sqlConnectionFactory.GetOpenConnection();

            string filter = string.Empty;

            if (!string.IsNullOrWhiteSpace(request.Filter))
            {
                filter = @"
                AND q.[Id] IN (
		            SELECT qst.Id 
			            FROM questions.Questions qst
			            LEFT JOIN questions.Choices AS chc ON chc.[QuestionId] = qst.[Id]
		            WHERE qst.Question like '%' + @filter + '%' OR chc.Choice like '%' + @filter + '%'
	            )
                ";
            }

            string query = @$ "
            SELECT
                q.[Id],
        public async Task <List <GetQuestionsDto> > Handle(GetQuestionsQuery request, CancellationToken cancellationToken)
        {
            var questions = await _dbContext.Questions.Include(c => c.Choices).ToListAsync();

            var questionsDto = new List <GetQuestionsDto>();

            foreach (var question in questions)
            {
                var qDto = new GetQuestionsDto
                {
                    QuestionId   = question.QuestionId,
                    QuestionText = question.QuestionText,
                    Choices      = question.Choices.Select(c => new GetChoicesByQuestionDto
                    {
                        ChoiceId   = c.ChoiceId,
                        ChoiceText = c.ChoiceText
                    }).ToList()
                };
                questionsDto.Add(qDto);
            }
            ;
            return(questionsDto);
        }
Exemplo n.º 6
0
 public async Task <IEnumerable <Questions> > Handle(GetQuestionsQuery request, CancellationToken cancellationToken)
 {
     return(await _context.Questions.ToListAsync(cancellationToken));
 }