I am consuming an api which returns me as response the following:
{
"rows": {
"recordset": [
{
"Monto": "10000000",
"CantidadDias": 50,
"TasaDiaria": "0.009700000000000",
"TasaPeriodo": "0.48",
"MontoInteres": 48000,
"MontoFinal": 10048000
}
]
}
}
The problem I have is that I do not know how to consume that data, starting with the model and then consuming it in the controller.
My controller: (It is a method that is in the controller)
private static async Task<object> NewMethod(object RootObject, HttpClient client)
{
client.BaseAddress = new Uri("http://0.0.0.0:0000/");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("authentication");
try
{
var department = new Rows { recordset = new List<Recordset>() };
HttpResponseMessage response = await client.PostAsJsonAsync("api/simuladorDAP", department);
if (response.IsSuccessStatusCode)
{
var EmpResponse = response.Content.ReadAsStringAsync().Result;
RootObject = JsonConvert.DeserializeObject<Recordset>(EmpResponse);
}
}
catch (Exception e)
{
throw (e);
}
return RootObject;
}
To make the post you must pass 2 parameters, here I do not know how to fill the list that I have in this line to pass those two parameters.
The parameters are Amount and Amount.
var department = new Rows {recordset = new List ()};
My model:
public class Recordset
{
public string Monto { get; set; }
public int CantidadDias { get; set; }
public string TasaDiaria { get; set; }
public string TasaPeriodo { get; set; }
public int MontoInteres { get; set; }
public int MontoFinal { get; set; }
}
public class Rows
{
public List<Recordset> recordset { get; set; }
}
public class RootObject
{
public Rows rows { get; set; }
}
They could indicate to me how I should do it please or that I am wrong. Thanks.