public static async void TestTrigger(string dbName, string collName) { await Task.Run( async() => { using (var client = new DocumentClient(new Uri(cStrEndPoint), cStrKey)) { FoodDocType fd = new FoodDocType { id = "TestFoodDoc", description = "Organic food", isFromSurvey = false, foodGroup = "Organic", version = 1 }; string url = "dbs" + "/" + dbName + "/colls/" + collName; try { Document issue = await client.CreateDocumentAsync(url, fd, new RequestOptions { PreTriggerInclude = new[] { "preTrigValidateIdExists" } }); } catch (Exception ex) { Console.WriteLine("Exception: " + ex.ToString()); } } }); }
public static async void CreateDoc(string dbName, string collName) { await Task.Run( async() => { using (var client = new DocumentClient(new Uri(cStrEndPoint), cStrKey)) { FoodDocType fd = new FoodDocType { id = "TestFoodDoc", description = "Organic food", isFromSurvey = false, foodGroup = "Organic", version = 1 }; Document issue = await CreateDocType(fd, client, dbName, collName); } }); }
public static async Task <Document> CreateDocType(FoodDocType fd, DocumentClient client, string dbName, string collName) { if (client != null) { string url = "dbs" + "/" + dbName + "/colls/" + collName; Document id = await client.CreateDocumentAsync(url, fd); return((id != null) ? client.CreateDocumentQuery(url). Where(d => d.Id == id.Id).AsEnumerable().FirstOrDefault() : null); } else { return(null); } }
public static void ListFoodDocType(FoodDocType fd, DocumentClient client, string dbName, string collName) { if (client != null) { IEnumerable <FoodDocType> docs = from c in client.CreateDocumentQuery <FoodDocType>("dbs" + "/" + dbName + "/colls/" + collName) where c.description.ToUpper(). Contains(fd.description.ToUpper()) select c; if (docs != null) { foreach (var doc in docs) { Console.WriteLine("id: {0}", doc.id); Console.WriteLine("description: {0}", doc.description); Console.WriteLine("Version: {0}", doc.version); Console.WriteLine("isFromSurvey: {0}", doc.isFromSurvey.ToString()); Console.WriteLine("foodGroup: {0}", doc.foodGroup); } } } }