public static Presentation Presentation(ExistingPresentation presentation) { switch (presentation) { case ExistingPresentation.TheHitchhikersGuideToTheCosoms: return(TheHitchhikersGuideToTheCosmos()); case ExistingPresentation.GraphingYourWayThroughTheCosoms: return(GraphingYourWayThroughTheCosoms()); case ExistingPresentation.EventDrivenArchitectureInTheCloud: return(EventDrivenArchitectureInTheCloud()); default: return(null); } }
/// <summary> /// Add the specified existing presentation to the database (if it does not already exists. /// </summary> /// <param name="existingPresentation">Identifier of the existing presentation to be added to the database.</param> private async Task AddPresentation(ExistingPresentation existingPresentation) { Presentation presentation = Generate.Presentation(existingPresentation); try { // Read the item to see if it exists. ReadItemAsync will throw an exception if the item does not exist and return status code 404 (Not found). ItemResponse <Presentation> presentationResponse = await this.container.ReadItemAsync <Presentation>(presentation.Id, new PartitionKey(presentation.OwnerEmailAddress)); Console.WriteLine("Item in database with id: {0} already exists\n", presentationResponse.Resource.Id); } catch (CosmosException ex) when(ex.StatusCode == HttpStatusCode.NotFound) { // Create an item in the container representing the presentation. Note we provide the value of the partition key for this item, which is "Andersen" ItemResponse <Presentation> presentationResponse = await this.container.CreateItemAsync <Presentation>(presentation, new PartitionKey(presentation.OwnerEmailAddress)); // Note that after creating the item, we can access the body of the item with the Resource property off the ItemResponse. // We can also access the RequestCharge property to see the amount of RUs consumed on this request. Console.WriteLine("Created item in database with id: {0} Operation consumed {1} RUs.\n", presentationResponse.Resource.Id, presentationResponse.RequestCharge); } }