public async Task <T> FindByIdAsync(Guid id)
        {
            var filter = Builders <T> .Filter.Eq(d => d.Id, id);

            var document = await _collection.FindAsync(filter).Result.FirstOrDefaultAsync();

            if (document == null)
            {
                throw EntityNotFoundException.OfType <T>(id);
            }
            return(document);
        }
Exemplo n.º 2
0
        public async Task ReplaceOneAsync(T document)
        {
            if (document == null)
            {
                throw new BadRequestException($"Document {typeof(T).ToString().Split('.').Last()} was not provided.");
            }

            var filter = Builders <T> .Filter.Eq(d => d.Id, document.Id);

            var doc = await _collection.FindAsync(filter).Result.FirstOrDefaultAsync();

            if (doc == null)
            {
                throw EntityNotFoundException.OfType <T>(document.Id);
            }
            await _collection.ReplaceOneAsync(filter, document);
        }