private async Task <IEnumerable <EventDocument> > GetEventDocumentsBackward(Expression <Func <EventDocument, bool> > predicate, int start, int count) { var skipCount = start < 1 ? 0 : start - 1; return(await Task.FromResult(_cosmosClient.GetDocumentQuery(predicate, _cosmosDBConfigurations.EventContainerName) .OrderByDescending(e => e.Position) .Skip(skipCount) .Take(count) .ToList())); }
async Task <IEnumerable <EventDocument> > IOperationHandler <GetEventDocumentsForward, IEnumerable <EventDocument> > .Handle(GetEventDocumentsForward operation, CancellationToken cancellationToken) { var skipCount = operation.Start < 1 ? 0 : operation.Start - 1; var result = new List <EventDocument>(); await _cosmosClient.GetDocumentQuery(operation.Predicate, _cosmosDBConfigurations.EventContainerName) .OrderBy(e => e.Position) .Skip(skipCount) .Take(operation.Count) .ToFeedIterator(eDoc => result.Add(eDoc)) .ConfigureAwait(false); return(result); }
private async Task <Optional <SnapshotDocument> > GetLastSnapshotStreamDocumentByIdAsync(string id) { try { var document = _cosmosDbClient .GetDocumentQuery <SnapshotDocument>(stream => stream.StreamId == id, _cosmosDBConfigurations.SnapshotContainerName) .OrderByDescending(s => s.EventPosition) .ToList() .FirstOrDefault(); return(document.ToOptional()); } catch (CosmosException) { return(Optional <SnapshotDocument> .Empty); } }