Inserting POCOs
Now we will write the generalized InsertCompetition
asynchronous method, which receives a Competition
instance, inserts it into the document collection, and displays a message indicating that the competition with a specific status and title has been created. Add the following lines to the existing code of the Program.cs
file. The code file for the sample is included in the learning_cosmos_db_05_01
folder in the SampleApp2/SampleApp1/Program.cs
file:
private static async Task<Competition> InsertCompetition(Competition competition) { var documentResponse = await client.CreateDocumentAsync(collectionUri, competition); if (documentResponse.StatusCode == System.Net.HttpStatusCode.Created) { Console.WriteLine($"The {competition.Status} competition with the title {competition.Title} has been created."); } Competition insertedCompetition = (dynamic) documentResponse.Resource; return insertedCompetition; }
The first line calls the...