Skip to content

Instantly share code, notes, and snippets.

View dontpaniclabsgists's full-sized avatar

Don't Panic Labs dontpaniclabsgists

View GitHub Profile
using (var client = new DocumentClient(new Uri(_endpoint), _key))
var link = UriFactory.CreateDocumentCollectionUri(_databaseId, CollectionId);
var query = client.CreateDocumentQuery<Note>(
link,
new FeedOptions()
{
EnableCrossPartitionQuery = true
})
.AsDocumentQuery();
var results = new List<Note>();
while (query.HasMoreResults)
{
results.AddRange(await query.ExecuteNextAsync<Note>());
}
return results.OrderBy(x => x.Id).ToArray();
public async Task<Note> Create(Note note)
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentCollectionUri(_databaseId, CollectionId);
await client.CreateDocumentAsync(link, note);
return note;
}
}
public async Task<Note> Update(Note note)
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentUri(_databaseId, CollectionId, note.Id);
await client.ReplaceDocumentAsync(link, note);
return note;
}
}
public async Task Delete(string id, string customerId)
{
using (var client = new DocumentClient(new Uri(_endpoint), _key))
{
var link = UriFactory.CreateDocumentUri(_databaseId, CollectionId, id);
await client.DeleteDocumentAsync(link, new RequestOptions()
{ PartitionKey = new Microsoft.Azure.Documents.PartitionKey(customerId)});
}
}
class NotesAccessor
{
const string CollectionId = "notes";
private string _endpoint;
private string _key;
private string _databaseId;
public NotesAccessor(string endpoint, string key, string databaseId)
{
class Program
{
static void Main(string[] args)
{
var endpoint = args[0];
var key = args[1];
var databaseId = args[2];
Task.Run(async () =>
{
dotnet new sln