i need to create an api in which final output would be look like that:-
{
"authdata": {
"version": "1.0",
"Type": "APIResponse",
"PDateTime": "9/14/2022 6:18:34 AM",
"status": "SUCCESS"
},
"data": [
{
"orderID": "",
"Orderdetails ": [
{
"orderNumber": "291323150",
"ID": "0001",
"orderDate": "9/2/2022 12:00:00 AM",
}
],
"Partdetails ": [
{
"key": "pincode",
"value": "34598702"
},
{
"key": "deliveryStatus",
"value": "OptedOut"
},
{
"key": "deliveryDate",
"value": "2022-09-02T00:00:00"
},
{
"key": "Status",
"value": "successfully dispatch"
}
]
}
]
}
to get such json response i create this modal:-
public class myResponse
{
public Authdata authdata { get; set; }
public List<orderdata> data { get; set; }
}
public class Authdata
{
public string version { get; set; }
public string Type { get; set; }
public string PDateTime { get; set; }
public string status { get; set; }
}
public class orderdata
{
public string orderID { get; set; }
[JsonProperty("Orderdetails ")]
public List<Orderdetail> Orderdetails { get; set; }
[JsonProperty("Partdetails ")]
public List<Partdetail> Partdetails { get; set; }
}
public class Orderdetail
{
public string orderNumber { get; set; }
public string ID { get; set; }
public string orderDate { get; set; }
}
public class Partdetail
{
public string key { get; set; }
public object value { get; set; }
}
now i have a function in which i passed all the data list and bind assemble it as per my output response
private myResponse outputResponse(List<od> odData, List<pd> pdData,string oid)
{
return new myResponse
{
authdata = new Authdata
{
version = "1.0",
Type = "APIResponse",
PDateTime = "9/14/2022 6:18:34 AM",
status ="SUCCESS"
},
data = new List<orderdata>
{
orderID = oid,
Orderdetails = odData
Partdetails = pdData
}
};
}
It's give me an error that orderdata does not contain a defination of orderID,Orderdetails,Partdetails.
can any one sugguest me the solution to implement this.
What I have tried:
i changed my modal code from this:
public class myResponse
{
public Authdata authdata { get; set; }
public List<orderdata> data { get; set; }
}
to this
public class myResponse
{
public Authdata authdata { get; set; }
public orderdata data { get; set; }
}
it's working but not getting expected result.