public async Task <IEnumerable <CreatureReadModel> > Handle(FindCreaturesQuery query, CancellationToken cancellationToken) { var monsterList = await _database.GetCollection <MonsterList>("monsterLists").AsQueryable() .Where(x => x.Name == query.MonsterList) .SingleOrDefaultAsync(cancellationToken); var collection = _database.GetCollection <Creature>("creatures"); var q = collection.AsQueryable(); q = monsterList == null ? q : q.Where(x => monsterList.Members.Contains(x.Name)); var creatures = await q .OrderBy(x => x.Name) .ToListAsync(cancellationToken); await LoadGear(creatures.ToArray()); return(_mapper.Map <IEnumerable <CreatureReadModel> >(creatures)); }
public Task <IEnumerable <CreatureReadModel> > Find(FindCreaturesQuery query, CancellationToken cancellationToken) { return(_mediator.Send(query ?? new FindCreaturesQuery(), cancellationToken)); }