Skip to content

Instantly share code, notes, and snippets.

@jstawski
Created November 18, 2014 23:35
Show Gist options
  • Save jstawski/dcacc601c6f5cfbe4b24 to your computer and use it in GitHub Desktop.
Save jstawski/dcacc601c6f5cfbe4b24 to your computer and use it in GitHub Desktop.
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Client;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DocDbToString
{
class Program
{
const string DBLINK = "[DBLINK]";
const string COLLECTIONLINK = "[COLLECTIONLINK]";
const string ENDPOINT = "https://your.endpoint";
const string AUTHKEY = "[AUTHKEY]";
static void Main(string[] args)
{
Run().Wait();
}
static async System.Threading.Tasks.Task Run()
{
using (var client = new DocumentClient(new Uri(ENDPOINT), AUTHKEY))
{
var task = new Task
{
Name = "Hello",
Reminders = new List<Reminder> { new Reminder { Reminded = false } }
};
var database = new Database();
database = await client.ReadDatabaseAsync(DBLINK);
var collection = new DocumentCollection();
collection = await client.ReadDocumentCollectionAsync(COLLECTIONLINK);
var taskDoc = await client.CreateDocumentAsync(collection.SelfLink, task);
//Read document
var newTask = (Task)(dynamic)(await client.ReadDocumentAsync(taskDoc.Resource.SelfLink)).Resource;
newTask.Reminders.First().Reminded = true;
Console.WriteLine(newTask.Reminders.First().Reminded);
Console.WriteLine(newTask.ToString());
await client.ReplaceDocumentAsync(newTask);
}
}
}
public class Task : Document
{
[JsonProperty(PropertyName = "name")]
public string Name { get; set; }
[JsonProperty(PropertyName = "reminders")]
public IEnumerable<Reminder> Reminders { get; set; }
}
public class Reminder
{
[JsonProperty(PropertyName = "reminded")]
public bool Reminded { get; set; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment