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:
Jovan Popovic
2016-08-02 16:29:13 -07:00
parent 89e879c06b
commit eab6c5fa9a
5 changed files with 17 additions and 6 deletions
@@ -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,