mercredi 5 avril 2017

Web API Post get related data from json.stringify

I have an html page with a button on it. Here are the functions that are important:

function updateClick() {
        SOP10100 = new Object();
        SOP10100.CUSTNMBR = "5000";
        SOP10100.SHIPMTHD = "FedEX";
        SOP10100.SOP10200 = [{ itemnmbr: "120604", quantity: 3, unitprice: .98, uofm: "ROLL" }, { itemnmbr: "120604", quantity: 1, unitprice: 4.98, uofm: "6 ROLL" }, { itemnmbr: "120604", quantity: 2, unitprice: 10.98, uofm: "12 ROLL" }]

        salesOrderCreate(SOP10100);
    }
function salesOrderCreate(sOP10100) {
       $.ajax({
            url: '/api/SOP10100',
            type: 'POST',
            contentType: "application/json;charset=utf-8",
            data: JSON.stringify(sOP10100),
            success: function (data) {
                salesOrderSuccess(data);
            },
            error: function (request, message, error) {
                handleException(request, message, error);
            }
        });
    }

Here is the controller that handles the click:

' POST: api/SOP10100
    <ResponseType(GetType(SOP10100))>
    Function PostSOP10100(ByVal sOP10100 As SOP10100) As IHttpActionResult
        If Not ModelState.IsValid Then
            Return BadRequest(ModelState)
        End If

        Try
'create the document header
            Dim otaSOPHdrIvcInsert As New Serialization.taSopHdrIvcInsert

            'populate the header
            With otaSOPHdrIvcInsert
                .DOCID = "EQ SALE ORD"
                .BACHNUMB = "webOrder"
                .LOCNCODE = "WAREHOUSE"
                .DOCDATE = DateString 'Today
                .CUSTNMBR = sOP10100.CUSTNMBR
                .SHIPMTHD = sOP10100.SHIPMTHD
                .REFRENCE = sOP10100.REFRENCE
End With

Here is where I'm stuck. I need to loop through the SOP10200 (which are the order lines) and for each one do something like this:

Dim otaSOPLineIvcInsert As New Serialization.taSopLineIvcInsert_ItemsTaSopLineIvcInsert

                With otaSOPLineIvcInsert
                    .SOPNUMBE = strSopNumber
                    .SOPTYPE = 2
                    .DOCDATE = DateString
                    .ITEMNMBR = sOP10100.SOP10200.itemnmbr
                End With

But I can't seem to be able to get to the itemnmbr in code. I can see it when debugging, so I know it is there.

If this wasn't coming from an API but a linq query i would do a query and then

For Each IV00101 In query

Any help on this would be greatly appreciated. I know the code is in VB, but the problem also applies to C#.




Aucun commentaire:

Enregistrer un commentaire