Beispiel #1
0
        public async Task <Example> GetExample(Guid id)
        {
            IMongoCollection <ExampleDocument> collection = GetCollection();

            ExampleDocument document = await collection.Find(doc => doc.Id == id).FirstOrDefaultAsync();

            return(document is null ? null : new Example(document.Id, document.Content));
        }
        public async Task <ExampleDto> Handle(GetExample request, CancellationToken cancellationToken)
        {
            IMongoCollection <ExampleDocument> collection =
                _mongoCollectionProvider.GetMongoDocumentCollection <ExampleDocument>();

            ExampleDocument result = await collection
                                     .Find(x => x.Id == request.Id)
                                     .FirstOrDefaultAsync(cancellationToken);

            if (result is null)
            {
                return(null);
            }

            return(new ExampleDto
            {
                Id = result.Id,
                Content = result.Content
            });
        }