Skip to content

Instantly share code, notes, and snippets.

View dontpaniclabsgists's full-sized avatar

Don't Panic Labs dontpaniclabsgists

View GitHub Profile
public async Task<Note[]> All()
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentCollectionUri(_databaseId, CollectionId);
var query = client.CreateDocumentQuery<Note>(
link,
new FeedOptions()
{
var link = UriFactory.CreateDocumentUri(_databaseId, CollectionId, id);
var note = await client.ReadDocumentAsync<Note>(link,
new RequestOptions()
{
PartitionKey = new Microsoft.Azure.Documents.PartitionKey(customerId)
});
public async Task<Note> ReadOne(string id, string customerId)
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentUri(_databaseId, CollectionId, id);
var note = await client.ReadDocumentAsync<Note>(link,
new RequestOptions()
{
PartitionKey = new Microsoft.Azure.Documents.PartitionKey(customerId)
public async Task<int> Count()
{
return (await All()).Length;
}
public async Task<int> Count()
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentCollectionUri(_databaseId, CollectionId);
var count = client.CreateDocumentQuery<Note>(
link,
new FeedOptions()
{
public async Task<PageResult> Page(string token, int pageSize, string customerId)
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentCollectionUri(_databaseId, CollectionId);
var querySetup = client.CreateDocumentQuery<Note>(
link,
new FeedOptions()
{
string token = null;
while (true)
{
var result = await accessor.Page(token, 2, customerId);
if (result.Notes.Length > 0)
{
var text = JsonConvert.SerializeObject(result.Notes);
token = result.Token;
Console.WriteLine("PAGE: " + text);
}
class Note
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "customerid")]
public string CustomerId { get; set; }
[JsonProperty(PropertyName = "text")]
public string Text { get; set; }
public async Task<Note[]> All()
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentCollectionUri(_databaseId, CollectionId);
var query = client.CreateDocumentQuery<Note>(
link,
new FeedOptions()
{