I have seen some code in "orderdemo" project.
---------------------
PB client side code that consumes web api....
--------------------------
String ls_url
String ls_response
String ls_json
JsonPackage lnv_package
Int li_return
lnv_package = Create JsonPackage
lnv_package.SetValueByDataWindow("order", adw_order, true)
lnv_package.SetValueByDataWindow("orderitems", adw_orderitems, true)
ls_url = gn_RESTClient.of_get_url("WOrderNew", "UeSave")
If gn_RESTClient.of_post(ls_url, lnv_package) > 0 Then
li_return = 1
Else
li_return = -1
End If
Destroy lnv_package
Return li_return
----------------------------------------------------------------------------
------------------
Web api side
------------------
// POST api/WOrderNew/UeSave
[HttpPost]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
public ActionResult UeSave(IDataUnpacker dataUnpacker)
{
// Declare and initialize local .NET DataStore variables
// By getting the Packaged DataStores
IDataStore order = dataUnpacker.GetDataStore("order");
IDataStore orderItems = dataUnpacker.GetDataStore("orderitems");
// Check if the modification was successful
if (_service.UeSave(order, orderItems))
{
// Return Status Code 200
return Ok();
}
else
{
// Return a Status Code 500 for Internal Server Error
return StatusCode(StatusCodes.Status500InternalServerError);
}
}
My question is that,
Is it possible to use JSONPackage object non-PB clients? Or how can I consume UeSave API any other type client such as java script or mobile client?
Regards and Thanks
There is no problem with Datastore object, if you only need to retrieve data. Since It can export plain text JSON(Datastore.ExportJson()).
But when it comes to tracsactional operation such as update, create etc,
Power Builder Client sent a json as follows below. That complex message can be mapped to Datawindow by Dataunpacker object.
My question is that how Datastore can process other type client message
those send plain JSON text like Angular or native mobile client. Otherwise I have to use Modelstore object for that purpose.
It means much more coding to have the same result.
{
"order": {
"identity": "70c86603-983b-4bd9-adbc-259436e43cbd",
"version": 1,
"platform": "PowerBuilder",
"mapping-method": 0,
"dataobject": {
"name": "d_order_modify",
"meta-columns": [{
"name": "forderno",
"index": 0,
"datatype": "string",
"nullable": 1
}, {
"name": "fcustno",
"index": 1,
"datatype": "string",
"nullable": 1
}, {
"name": "fstatus",
"index": 2,
"datatype": "string",
"nullable": 1
}, {
"name": "forderdate",
"index": 3,
"datatype": "date",
"nullable": 1
}, {
"name": "ftype",
"index": 4,
"datatype": "string",
"nullable": 1
}, {
"name": "famount",
"index": 5,
"datatype": "decimal",
"nullable": 1
}, {
"name": "fpaid",
"index": 6,
"datatype": "string",
"nullable": 0
}, {
"name": "fdescription",
"index": 7,
"datatype": "string",
"nullable": 1
}
],
"primary-rows": [{
"row-status": 1,
"columns": {
"forderno": ["101008"],
"fcustno": ["1010"],
"fstatus": ["1"],
"forderdate": ["2016-10-17", 1, "2016-08-17 00:00:00"],
"ftype": ["Phone"],
"famount": [72],
"fpaid": ["0"],
"fdescription": [null]
}
}
]
}
},
"orderitems": {
"identity": "70c86603-983b-4bd9-adbc-259436e43cbd",
"version": 1,
"platform": "PowerBuilder",
"mapping-method": 0,
"dataobject": {
"name": "d_orderitem_edit",
"meta-columns": [{
"name": "fcategory",
"index": 0,
"datatype": "string",
"nullable": 1
}, {
"name": "fproname",
"index": 1,
"datatype": "string",
"nullable": 1
}, {
"name": "fdescription",
"index": 2,
"datatype": "string",
"nullable": 1
}, {
"name": "fquantity",
"index": 3,
"datatype": "decimal",
"nullable": 1
}, {
"name": "fsku",
"index": 4,
"datatype": "string",
"nullable": 1
}, {
"name": "funit_price",
"index": 5,
"datatype": "decimal",
"nullable": 1
}, {
"name": "flineid",
"index": 6,
"datatype": "long",
"nullable": 1
}, {
"name": "forderno",
"index": 7,
"datatype": "string",
"nullable": 1
}, {
"name": "famount",
"index": 8,
"datatype": "decimal",
"nullable": 1
}
],
"primary-rows": [{
"row-status": 0,
"columns": {
"fcategory": ["A"],
"fproname": ["Men's T-shirt, Blue"],
"fdescription": ["Men's high quality stretch short sleeve candy-colors T-shirt with round collar, blue"],
"fquantity": [1],
"fsku": ["A00008"],
"funit_price": [12],
"flineid": [5],
"forderno": ["101008"],
"famount": [12]
}
}, {
"row-status": 0,
"columns": {
"fcategory": ["A"],
"fproname": ["Men's T-shirt, Black"],
"fdescription": ["Men's high quality stretch short sleeve candy-colors T-shirt with round collar, black"],
"fquantity": [1],
"fsku": ["A01010"],
"funit_price": [12],
"flineid": [6],
"forderno": ["101008"],
"famount": [12]
}
}, {
"row-status": 0,
"columns": {
"fcategory": ["A"],
"fproname": ["Polo Shirt, White"],
"fdescription": ["Men's top quality short sleeve masculine turn-down collar casual polo shirt, white"],
"fquantity": [2],
"fsku": ["a22222"],
"funit_price": [24],
"flineid": [7],
"forderno": ["101008"],
"famount": [48]
}
}
]
}
}
}