How to walk through a C # class?

0

I have DeserializeObject that fills a request class and items, in the items I need to go through this class to write the data, the way I'm doing is zeroing the records, how could I read the data? >

public class Item
{
    public string idItemPedido { get; set; }
    public int item { get; set; }
    public string plano { get; set; }
    public Produto produto { get; set; }
    public string descricaoItem { get; set; }
    public decimal valorUnitario { get; set; }
    public string qtde { get; set; }
    public decimal valorTotal { get; set; }
    public string pontos { get; set; }
}

   string teste = "115873";
   GravaItensPedido(teste);


   public void GravaItensPedido(string CodigoCabecahoPedido)
        {
            var strQuery = "";
            IEnumerable<Item> enumeracao = new List<Item>();

            foreach (var item in enumeracao)
            {
                strQuery = "";
            }
        }
    
asked by anonymous 13.12.2017 / 21:18

2 answers

0

Do you want to generate an update / insert query for class properties?

If so, I recommend using Dapper to help you. It is a C # library created by the StackOverflow team.

It will help you a lot: Dapper

Look how cool:

var count = connection.Execute(@"
  set nocount on 
  create table #t(i int) 
  set nocount off 
  insert #t 
  select @a a union all select @b 
  set nocount on 
  drop table #t", new {a=1, b=2 });
Assert.Equal(2, count);

You get an ADO.NET connection, you will have an extension method called Execute . Then you call it with 2 parameters.

  • In 1 parameter you pass sql
  • In the 2nd parameter you pass an object, with the data to mount the query for you.

What about?

    
14.12.2017 / 01:58
0

There's something missing from your question, so

case 1: you inform the parameter (CodeCooking Order) and receives a list using some method

public void GravaItensPedido(string codigoCabecahoPedido)
{

      List<Item> minhaLista= getlistblabla(x=>x.CodigoCabecahoPedido == codigoCabecahoPedido);

      foreach (var itens in minhaLista)
      {
         //Faz alguma coisa
      }
}

case 2: you pass the list that will be changed or something like

public void GravaItensPedido(string codigoCabecahoPedido, List<Item> itens)
{      
  var strQuery = "";

  foreach (var itens in itens)
  {
      if(codigoCabecahoPedido == "test")
      {
        //faca alguma coisa
      }
  }
}
    
14.12.2017 / 07:30