1
I have an api that when receiving the data fills a class, I want to do a while in this class tb_dados_api and tb_carrinho, take the data to record in the database, how could I do that? Thanks
Here I am getting the data
[HttpPost]
[Route("unidade/carrinho/ConsultaUnidadeAtendimento")]
public HttpResponseMessage ConsultaUnidadeAtendimento(TB_DADOS_API consultaAtendimento)
{
try
{
string numeroCarrinho = consultaAtendimento.NumeroCarrinho.ToString();
string cep = consultaAtendimento.Cep;
bool retiraLocal = consultaAtendimento.RetiraNoLocal;
var tTabela = new ConsultaUnidadeEstoque();
var listar = tTabela.SelecionaUnidadeAtendimento(cep);
return Request.CreateResponse(HttpStatusCode.OK, new { dados = listar.ToArray() });
}
catch (Exception ex)
{
return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message);
}
}
They fill the class:
public class TB_DADOS_API
{
[JsonProperty("numeroCarrinho")]
public long NumeroCarrinho { get; set; }
[JsonProperty("itens")]
public List<TB_CARRINHO> Itens { get; set; }
[JsonProperty("cep")]
public string Cep { get; set; }
[JsonProperty("retiraNoLocal")]
public bool RetiraNoLocal { get; set; }
}
public class TB_CARRINHO
{
[JsonProperty("codigo")]
public string Codigo { get; set; }
[JsonProperty("qtd")]
public int Qtd { get; set; }
}
ta using Entity framework or other Orm ?
– Eduardo Sampaio
I am not using Entity framework, I have the class filled, I want to read the data and write to the database
– Harry
can use foreach to access the objects and save all in a table put the example ai in the answer
– Eduardo Sampaio
I appreciate immensely the help, my idea was to make this foreach inside the method Consultationstock and not in this location, because there I have a routine that will select where will be recorded the items
– Harry