Skip to content

Commit

Permalink
Merge pull request #4 from Azure-Samples/add-code-formatting
Browse files Browse the repository at this point in the history
Add code comment blocks
  • Loading branch information
seesharprun authored Oct 11, 2023
2 parents 833a918 + 1be7bf6 commit a2c9b5d
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 25 deletions.
54 changes: 32 additions & 22 deletions src/web/Pages/Index.razor
Original file line number Diff line number Diff line change
Expand Up @@ -38,69 +38,78 @@

await WriteToConsoleAync("Current Status:\tStarting...");

// <get-database>
Database database = client.GetDatabase("cosmicworks");
// </get-database>
await WriteToConsoleAync($"Get database:\t{database.Id}");

// <get-container>
Container container = database.GetContainer("products");
// </get-container>
await WriteToConsoleAync($"Get container:\t{container.Id}");

{
Product item = new(
id: "68719518391",
category: "gear-surf-surfboards",
name: "Yamba Surfboard",
quantity: 12,
price: 850.00m,
clearance: false
// <create-item>
Product item = new(
id: "68719518391",
category: "gear-surf-surfboards",
name: "Yamba Surfboard",
quantity: 12,
price: 850.00m,
clearance: false
);

ItemResponse<Product> response = await container.UpsertItemAsync<Product>(
item: item,
partitionKey: new PartitionKey("gear-surf-surfboards")
item: item,
partitionKey: new PartitionKey("gear-surf-surfboards")
);
// </create-item>
await WriteToConsoleAync($"Upserted item:\t{response.Resource}");
await WriteToConsoleAync($"Status code:\t{response.StatusCode}");
await WriteToConsoleAync($"Request charge:\t{response.RequestCharge:0.00}");
}

{
Product item = new(
id: "68719518371",
category: "gear-surf-surfboards",
name: "Kiama Classic Surfboard",
quantity: 25,
price: 790.00m,
clearance: false
id: "68719518371",
category: "gear-surf-surfboards",
name: "Kiama Classic Surfboard",
quantity: 25,
price: 790.00m,
clearance: false
);

ItemResponse<Product> response = await container.UpsertItemAsync<Product>(
item: item,
partitionKey: new PartitionKey("gear-surf-surfboards")
item: item,
partitionKey: new PartitionKey("gear-surf-surfboards")
);
await WriteToConsoleAync($"Upserted item:\t{response.Resource}");
await WriteToConsoleAync($"Status code:\t{response.StatusCode}");
await WriteToConsoleAync($"Request charge:\t{response.RequestCharge:0.00}");
}

{
// <read-item>
ItemResponse<Product> response = await container.ReadItemAsync<Product>(
id: "68719518391",
partitionKey: new PartitionKey("gear-surf-surfboards")
id: "68719518391",
partitionKey: new PartitionKey("gear-surf-surfboards")
);
// </read-item>
await WriteToConsoleAync($"Read item id:\t{response.Resource.id}");
await WriteToConsoleAync($"Read item:\t{response.Resource}");
await WriteToConsoleAync($"Status code:\t{response.StatusCode}");
await WriteToConsoleAync($"Request charge:\t{response.RequestCharge:0.00}");
}

{
// <query-items>
var query = new QueryDefinition(
query: "SELECT * FROM products p WHERE p.category = @category"
query: "SELECT * FROM products p WHERE p.category = @category"
)
.WithParameter("@category", "gear-surf-surfboards");
.WithParameter("@category", "gear-surf-surfboards");

using FeedIterator<Product> feed = container.GetItemQueryIterator<Product>(
queryDefinition: query
queryDefinition: query
);
await WriteToConsoleAync($"Ran query:\t{query.QueryText}");

Expand All @@ -113,6 +122,7 @@
}
await WriteToConsoleAync($"Request charge:\t{response.RequestCharge:0.00}");
}
// </query-items>
}

await WriteToConsoleAync("Current Status:\tStopping...");
Expand Down
9 changes: 6 additions & 3 deletions src/web/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();

builder.Services.AddSingleton<CosmosClient>((_) => new CosmosClient(
accountEndpoint: builder.Configuration["AZURE_COSMOS_DB_NOSQL_ENDPOINT"]!,
tokenCredential: new DefaultAzureCredential()
builder.Services.AddSingleton<CosmosClient>((_) =>
// <create-client>
new CosmosClient(
accountEndpoint: builder.Configuration["AZURE_COSMOS_DB_NOSQL_ENDPOINT"]!,
tokenCredential: new DefaultAzureCredential()
// </create-client>
));

var app = builder.Build();
Expand Down

0 comments on commit a2c9b5d

Please sign in to comment.