I got an error about the serialization of the object when the LINQ expression contained OrderLines = x.OrderLines Also it shouldn't be the OrderId but actually the OrderNumber I want to search for.
Now I have this, which returns basic info about the order and the an array of the orderlines. I'm not sure if it could be shorten or there is a way to return all properties in each OrderLine to strings? Right now I select some specific properties..
public string GetOrderDetails(string orderNumber)
{
var purchaseOrder =
PurchaseOrder.All().Single(x => x.OrderNumber == orderNumber && x.OrderStatus.OrderStatusId != 1);
var orderLines = new List<string[]>();
foreach (OrderLine ol in purchaseOrder.OrderLines)
{
var li = new string[]
{
ol.OrderLineId.ToLowerInvariantString(),
ol.Sku,
ol.ProductName,
ol.Price.ToLowerInvariantString(),
ol.Quantity.ToLowerInvariantString()
};
orderLines.Add(li);
}
var o = new List<object>
{
purchaseOrder.OrderId,
purchaseOrder.CreatedDate,
purchaseOrder.OrderStatus.OrderStatusId,
purchaseOrder.OrderStatus.Name,
orderLines
};
return JsonConvert.SerializeObject(o);
}
Return Order Details as json
Hi..
How can I return order details as json in via the API?
E.g. I can do this to return json about an order using Newtonsoft.Json:
However this won't work just to add the OrderLines:
/Bjarne
Do you get any errors?
I got an error about the serialization of the object when the LINQ expression contained OrderLines = x.OrderLines
Also it shouldn't be the OrderId but actually the OrderNumber I want to search for.
Now I have this, which returns basic info about the order and the an array of the orderlines. I'm not sure if it could be shorten or there is a way to return all properties in each OrderLine to strings? Right now I select some specific properties..
/Bjarne
As long as it works i guess you're good to go :)
is working on a reply...