Beispiel #1
0
        public override async Task <ActionResult <List <PhraseDto> > > Handle(ListPhrasesByTermCommand command)
        {
            var phrases = await _listPhrasesQuery.Query(command);

            if (phrases == null)
            {
                return(Error());
            }

            var phrasesDto = _mapper.Map(phrases, new List <PhraseDto>());

            return(Ok(phrasesDto));
        }
        public override async Task <List <Phrase> > Query(ListPhrasesByTermCommand command)
        {
            var query = DbContext.Phrases
                        .Where(o => o.Value.StartsWith(command.Term, StringComparison.CurrentCultureIgnoreCase))
                        .Select(o => o.Value)
                        .Distinct()
                        .Take(5);

            var result = await query.ToListAsync();

            return(result.Select(o => new Phrase()
            {
                Value = o
            }).ToList());
        }