private async Task GetStartedDemo() { using (var client = new DocumentClient(new Uri(EndpointUrl), PrimaryKey)) { Database database = client.CreateDatabaseQuery().Where(db => db.Id == "WinoDB").AsEnumerable().FirstOrDefault(); if (database == null) { database = await client.CreateDatabaseAsync( new Database { Id = "WinoDB" }); } DocumentCollection documentCollection = client.CreateDocumentCollectionQuery(database.CollectionsLink).Where(c => c.Id == "WinoDB").AsEnumerable().FirstOrDefault(); if (documentCollection == null) { documentCollection = await client.CreateDocumentCollectionAsync(database.CollectionsLink, new DocumentCollection { Id = "WinoDB" }, new RequestOptions { OfferType = "S1" }); } Document document = client.CreateDocumentQuery(documentCollection.DocumentsLink).Where(d => d.Id == "1").AsEnumerable().FirstOrDefault(); if (document == null) { Drinkz tyskie = new Drinkz { Id = "1", Name = "Tyskie klasyczne", Type = "Piwo", Companies = new Company { Name = "Tyskie", Description = "Tyskie to obiekt pożądania austro-węgierskich szwarccharakterów", Addresses = new Address { Country = "Polska", City = "Tychy", Street = "Wojska Polskiego", Number = 12, PostalCode = "43-100" } }, Ingredients = new Ingredient[] { new Ingredient { Name = "Woda", Description = "świeża woda" }, new Ingredient { Name = "Alkohol", Percent = 4 }, new Ingredient { Name = "Słody jęczmienne", Description = "najlepsze słody jęczmienne" }, new Ingredient { Name = "Wyciąg z szyszki", Description = "wyciąg z sosnowych szyszek" } }, Price = 2.4, Quality = "Wysoka" }; await client.CreateDocumentAsync(documentCollection.DocumentsLink, tyskie); } } }
public async void AddDrink() { this.client = new DocumentClient(new Uri(EndpointUrl), PrimaryKey); Database database = client.CreateDatabaseQuery().Where(db => db.Id == "WinoDB").AsEnumerable().FirstOrDefault(); DocumentCollection documentCollection = client.CreateDocumentCollectionQuery(database.CollectionsLink).Where(c => c.Id == "WinoDB").AsEnumerable().FirstOrDefault(); var drinks = client.CreateDocumentQuery(documentCollection.DocumentsLink, "SELECT * from Drinks f"); int ID = 1; foreach (var drink in drinks) { ID++; } string id = ID.ToString(); Ingredient[] Ing = new Ingredient[ingAmount]; int per1, per2, per3, per4; if (perc1.Text != "") { per1 = Convert.ToInt32(perc1.Text); } else { per1 = 0; } Ing[0] = new Ingredient { Name = ingname1.Text, Description = ingdesc1.Text, Percent = per1 }; if (Ing.Length > 1) { if (textBox4.Text != "") { per2 = Convert.ToInt32(textBox4.Text); } else { per2 = 0; } Ing[1] = new Ingredient { Name = textBox5.Text, Description = richTextBox1.Text, Percent = per2 }; if (Ing.Length > 2) { if (textBox6.Text != "") { per3 = Convert.ToInt32(textBox6.Text); } else { per3 = 0; } Ing[2] = new Ingredient { Name = textBox7.Text, Description = richTextBox2.Text, Percent = per3 }; if (Ing.Length == 4) { if (textBox8.Text != "") { per4 = Convert.ToInt32(textBox8.Text); } else { per4 = 0; } Ing[3] = new Ingredient { Name = textBox9.Text, Description = richTextBox3.Text, Percent = per4 }; } } } int nr; if (housenr.Text != "") { nr = Convert.ToInt32(housenr.Text); } else { nr = 0; } Address Addr = new Address { Country = country.Text, City = city.Text, Street = street.Text, Number = nr, PostalCode = pcode.Text }; Company Comp = new Company { Name = compname.Text, Description = desc.Text, Addresses = Addr }; Drinkz d1 = new Drinkz { Id = id, Name = name.Text, Type = type.Text, Companies = Comp, Ingredients = Ing, Price = Convert.ToDouble(textBox3.Text), Quality = textBox2.Text }; await client.CreateDocumentAsync(documentCollection.DocumentsLink, d1); }
public async void EditDrink() { this.client = new DocumentClient(new Uri(EndpointUrl), PrimaryKey); Database database = client.CreateDatabaseQuery().Where(db => db.Id == "WinoDB").AsEnumerable().FirstOrDefault(); DocumentCollection documentCollection = client.CreateDocumentCollectionQuery(database.CollectionsLink).Where(c => c.Id == "WinoDB").AsEnumerable().FirstOrDefault(); string id = textBox11.Text; Ingredient[] Ing = new Ingredient[ingAmount]; int per1, per2, per3, per4; if (textBox28.Text != "") { per1 = Convert.ToInt32(textBox28.Text); } else { per1 = 0; } Ing[0] = new Ingredient { Name = textBox29.Text, Description = richTextBox8.Text, Percent = per1 }; if (Ing.Length > 1) { if (textBox26.Text != "") { per2 = Convert.ToInt32(textBox26.Text); } else { per2 = 0; } Ing[1] = new Ingredient { Name = textBox27.Text, Description = richTextBox7.Text, Percent = per2 }; if (Ing.Length > 2) { if (textBox24.Text != "") { per3 = Convert.ToInt32(textBox24.Text); } else { per3 = 0; } Ing[2] = new Ingredient { Name = textBox25.Text, Description = richTextBox6.Text, Percent = per3 }; if (Ing.Length == 4) { if (textBox22.Text != "") { per4 = Convert.ToInt32(textBox22.Text); } else { per4 = 0; } Ing[3] = new Ingredient { Name = textBox23.Text, Description = richTextBox5.Text, Percent = per4 }; } } } int nr; if (textBox18.Text != "") { nr = Convert.ToInt32(textBox18.Text); } else { nr = 0; } Address Addr = new Address { Country = textBox15.Text, City = textBox16.Text, Street = textBox17.Text, Number = nr, PostalCode = textBox19.Text }; Company Comp = new Company { Name = textBox14.Text, Description = richTextBox4.Text, Addresses = Addr }; Drinkz d1 = new Drinkz { Id = id, Name = textBox12.Text, Type = textBox13.Text, Companies = Comp, Ingredients = Ing, Price = Convert.ToDouble(textBox20.Text), Quality = textBox21.Text }; var uri = UriFactory.CreateDocumentUri("WinoDB", "WinoDB", id); await client.ReplaceDocumentAsync(uri, d1); }