mirror of
https://github.com/Microsoft/sql-server-samples.git
synced 2025-12-08 14:58:54 +00:00
Updated table to show some JSON fields
In product listing are shown made in fields from JSON and tags JSON colums
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
*.xproj.user
|
||||
.vs/*
|
||||
.vscode/*
|
||||
bin/*
|
||||
obj/*
|
||||
*.sln
|
||||
|
||||
@@ -25,14 +25,22 @@ namespace ProductCatalog.Controllers
|
||||
[HttpGet]
|
||||
public async Task Get()
|
||||
{
|
||||
await sqlQuery.Stream("select * from Product FOR JSON PATH, ROOT('data')", Response.Body, EMPTY_PRODUCTS_ARRAY);
|
||||
await sqlQuery.Stream(
|
||||
@"select ProductID, Name, Color, Price, Quantity, JSON_VALUE(Data, '$.MadeIn') as MadeIn, JSON_QUERY(Tags) as Tags
|
||||
from Product
|
||||
FOR JSON PATH, ROOT('data')", Response.Body, EMPTY_PRODUCTS_ARRAY);
|
||||
}
|
||||
|
||||
// GET api/Product/5
|
||||
[HttpGet("{id}")]
|
||||
public async Task Get(int id)
|
||||
{
|
||||
var cmd = new SqlCommand("select * from Product where ProductId = @id FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
|
||||
var cmd = new SqlCommand(
|
||||
@"select ProductID, Name, Color, Price, Quantity
|
||||
from Product
|
||||
where ProductId = @id
|
||||
FOR JSON PATH, WITHOUT_ARRAY_WRAPPER");
|
||||
|
||||
cmd.Parameters.AddWithValue("id", id);
|
||||
await sqlQuery.Stream(cmd, Response.Body, "{}");
|
||||
}
|
||||
|
||||
@@ -73,8 +73,8 @@ AS BEGIN
|
||||
Size = json.Size,
|
||||
Price = json.Price,
|
||||
Quantity = json.Quantity,
|
||||
Data = json.Data,
|
||||
Tags = json.Tags
|
||||
Data = ISNULL(json.Data, Data),
|
||||
Tags = ISNULL(json.Tags,Tags)
|
||||
FROM OPENJSON(@ProductJson)
|
||||
WITH ( Name nvarchar(100) N'strict $."Name"',
|
||||
Color nvarchar(30),
|
||||
|
||||
@@ -63,9 +63,10 @@
|
||||
<tr>
|
||||
<th>Product</th>
|
||||
<th>Color</th>
|
||||
<th>Size</th>
|
||||
<th>Price</th>
|
||||
<th>Quantity</th>
|
||||
<th>Made in</th>
|
||||
<th>Tags</th>
|
||||
<th></th>
|
||||
<th></th>
|
||||
</tr>
|
||||
|
||||
@@ -48,9 +48,10 @@ $(document).ready(function () {
|
||||
"columns": [
|
||||
{ "data": "Name" },
|
||||
{ "data": "Color", "defaultContent": "" },
|
||||
{ "data": "Size", "defaultContent": "" },
|
||||
{ "data": "Price", sType: 'numeric', "defaultContent": "" },
|
||||
{ "data": "Quantity", "visible": true, "defaultContent": "" },
|
||||
{ "data": "MadeIn", "visible": true, "defaultContent": "" },
|
||||
{ "data": "Tags", "visible": true, "defaultContent": "" },
|
||||
{
|
||||
"data": "ProductID",
|
||||
"sortable": false,
|
||||
|
||||
Reference in New Issue
Block a user