Output from my service does not match my password

1

In the output of my service, for the DataItems field, I have this:

<DadosItens>
Qtde 3 Custo 46,66Unitario 68,58 Margem 0Ult.Cond 30/01/2017 C. Diario 46,66 Total 205,73
</DadosItens>

It turns out that I do not have any Label Qtde or Cost or Margin or any other in my DTO which is what I export for the service. I tried yes, put those labels, but as I was giving error, not in the label, but the way I was doing, I removed them and left only the fields. And after I got everything right, I was rolling and it's coming like that and I do not know where it's fixed (the first time) so I can fix it, because I can not go up this way, because I do not know what's happening. This concatenation I made, because I need to play in a cell of my App Xamarin.Forms that fields all together in the same cell, because the client wants so and was not able to do in the App and Xamarin forum, gave me this tip. This is my DTO

public class ItensLibDTO
    {
        public string Produto { get; set; }
        public string Qtde { get; set; }
        public string Unitario { get; set; }
        public string MargemAvista { get; set; }
        public string Custo { get; set; }
        public string CustoDiario { get; set; }
        public string UltCondicao { get; set; }
        public string Total { get; set; }
        public string DadosItens
        {
            get
            {
                return Qtde.ToString() + " " + Custo.ToString() + "  " + Unitario.ToString() +
                  " " + MargemAvista.ToString() + " " + UltCondicao.ToString() + "  " +
                  CustoDiario.ToString() + " " + Total.ToString();
            }
            set
            {
                Qtde = value;
                Custo = value;
                Unitario = value;
                MargemAvista = value;
                UltCondicao = value;
                CustoDiario = value;
                Total = value;
            }
        }

And my class for the service

public class ItensLiberacao
    {
        AutorizadorContext contexto = new AutorizadorContext();
        ItensLibDTO libDTO = new ItensLibDTO();
        CultureInfo minhaCultura = new CultureInfo("pt-BR");

        [Route("itens/{id}")]
        public List<ItensLibDTO> getItensLib(int id)
        {
            var lista = contexto.ItensLibs
                .Where(itens => itens.IdOrcamento == id)
                .Select(item => new ItensLibDTO
                {
                    Produto = item.Produto,
                    Qtde = item.Qtde.ToString(),
                    Unitario = item.Unitario.ToString(),
                    MargemAvista = item.MargemAvista.ToString(),
                    Custo = item.Custo.ToString(),
                    CustoDiario = item.CustoDiario.ToString(),
                    UltCondicao = item.UltCondicao.ToString(),
                    Total = item.Total.ToString(),
                    DadosItens = item.Qtde.ToString() + " " + item.Custo.ToString() + "  " + item.Unitario.ToString() +
                                 " " + item.MargemAvista.ToString() + "  " + item.UltCondicao.ToString() + "  " + item.CustoDiario.ToString() +
                                 " " + item.Total.ToString()
                }).ToList();

            lista.ForEach(e => e.UltCondicao = new DateTime(1800, 12, 28).AddDays(float.Parse(e.UltCondicao)).ToString("dd/MM/yyyy"));

            lista.ForEach(e => e.Unitario = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Unitario, new CultureInfo("en").NumberFormat)));
            lista.ForEach(e => e.Custo = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Custo, new CultureInfo("en").NumberFormat)));
            lista.ForEach(e => e.CustoDiario = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.CustoDiario, new CultureInfo("en").NumberFormat)));

            lista.ForEach(e => e.Total = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Total, new CultureInfo("en").NumberFormat)));

            return lista;
        }
    }

See that I have no label or field name. As I said I had done so the first time, but did not turn, I was mistaken. First I removed them thinking to be them and then I saw that it had to do with the bank, there I left without them and now it is coming like this. How do I do? Restart PC, rs?

EDIT1

Whenever I give a clean solution I have problems. Resolved with the clean, the problem of the labels, but it is giving error in this line and in all that have similar lambdas, that is, all the foreach in the class Liberation Items. That line was just an example.

lista.ForEach(e => e.UltCondicao = new DateTime(1800, 12, 28).AddDays(float.Parse(e.UltCondicao)).ToString("dd/MM/yyyy"));

saying that the string is invalid. Guys, it was working before clean and I do not know what's happening, honestly. If all the foreach is commented on the class itensLiberacao, then the service goes up and without the labels. Reboot VS and still the error persists:

  

The input string was not in a correct format.

My website is working with this foreach, I just have not uploaded those changes yet.

EDIT2

I did so now

var lista = contexto.ItensLibs
                .Where(itens => itens.IdOrcamento == id)
                .Select(item => new ItensLibDTO
                {
                    Produto = item.Produto,
                    Qtde = item.Qtde.ToString(),
                    Unitario = item.Unitario.ToString(),
                    MargemAvista = item.MargemAvista.ToString(),
                    Custo = item.Custo.ToString(),
                    CustoDiario = item.CustoDiario.ToString(),
                    UltCondicao = item.UltCondicao.ToString(),
                    Total = item.Total.ToString()
                    //DadosItens = ""
                    //DadosItens = "Qtde " + item.Qtde.ToString() + " " + "Custo " + item.Custo.ToString() + "  " + "Uni. " + item.Unitario.ToString() +
                    //             " " + "Mar " + item.MargemAvista.ToString() + "  " + "Ul.Cond. " + item.UltCondicao.ToString() + "  " + "C.Dia " + item.CustoDiario.ToString() +
                    //             " " + " Total " + item.Total.ToString()
                }).ToList();

            lista.ForEach(e => e.UltCondicao = new DateTime(1800, 12, 28).AddDays(float.Parse(e.UltCondicao)).ToString("dd/MM/yyyy"));

            lista.ForEach(e => e.Unitario = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Unitario, new CultureInfo("en").NumberFormat)));
            lista.ForEach(e => e.Custo = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Custo, new CultureInfo("en").NumberFormat)));
            lista.ForEach(e => e.CustoDiario = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.CustoDiario, new CultureInfo("en").NumberFormat)));

            lista.ForEach(e => e.Total = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Total, new CultureInfo("en").NumberFormat)));

            lista.ForEach(e => e.DadosItens = "Qtde " + e.Qtde.ToString() + " " + "Custo " + e.Custo.ToString());

            return lista;

No more error, but service return repeats all values like this:

<ItensLibDTO>
<Custo>Qtde 3 Custo 46,66</Custo>
<CustoDiario>Qtde 3 Custo 46,66</CustoDiario>
<DadosItens>
Qtde 3 Custo 46,66 Qtde 3 Custo 46,66 Qtde 3 Custo 46,66 Qtde 3 Custo 46,66 Qtde 3 Custo 46,66 Qtde 3 Custo 46,66 Qtde 3 Custo 46,66
</DadosItens>
<MargemAvista>Qtde 3 Custo 46,66</MargemAvista>
<Produto>BASF CABRIO TOP 1KG LOTE: 158-15-4000 VAL 05/2017</Produto>
<Qtde>Qtde 3 Custo 46,66</Qtde>
<Total>Qtde 3 Custo 46,66</Total>
<UltCondicao>Qtde 3 Custo 46,66</UltCondicao>
<Unitario>Qtde 3 Custo 46,66</Unitario>
</ItensLibDTO>

It should be like this

<ItensLibDTO>
<Custo>46,66</Custo>
<CustoDiario>46,66</CustoDiario>
<DadosItens>3 46,66 68,58 0 30/01/2017 46,66 205,73</DadosItens>
<MargemAvista>0</MargemAvista>
<Produto>BASF CABRIO TOP 1KG LOTE: 158-15-4000 VAL 05/2017</Produto>
<Qtde>3</Qtde>
<Total>205,73</Total>
<UltCondicao>30/01/2017</UltCondicao>
<Unitario>68,58</Unitario>
</ItensLibDTO>

Data is commented on both the DTO and the service class

I do not know where this comes from, if I commented this field in both the DTO and the service class:

<DadosItens>3 46,66 68,58 0 30/01/2017 46,66 205,73</DadosItens>
    
asked by anonymous 13.09.2017 / 12:39

1 answer

0

I did not understand, but it did not work. I gave some cleans. Colleague Gabriel Colleta, told me nothing to do with Clean, but after giving a few (a 3), worked. So my code stayed: DTO

public class ItensLibDTO
    {
        public string Produto { get; set; }
        public string Qtde { get; set; }
        public string Unitario { get; set; }
        public string MargemAvista { get; set; }
        public string Custo { get; set; }
        public string CustoDiario { get; set; }
        public string UltCondicao { get; set; }
        public string Total { get; set; }
        public string DadosItens { get; set; }
    }

And the method you export to the service

public class ItensLiberacao
    {
        AutorizadorContext contexto = new AutorizadorContext();
        ItensLibDTO libDTO = new ItensLibDTO();
        //CultureInfo minhaCultura = new CultureInfo("pt-BR");

        [Route("itens/{id}")]
        public List<ItensLibDTO> getItensLib(int id)
        {
            var lista = contexto.ItensLibs
                .Where(itens => itens.IdOrcamento == id)
                .Select(item => new ItensLibDTO
                {
                    Produto = item.Produto,
                    Qtde = item.Qtde.ToString(),
                    Unitario = item.Unitario.ToString(),
                    MargemAvista = item.MargemAvista.ToString(),
                    Custo = item.Custo.ToString(),
                    CustoDiario = item.CustoDiario.ToString(),
                    UltCondicao = item.UltCondicao.ToString(),
                    Total = item.Total.ToString(),
                    DadosItens = ""
                }).ToList();

            lista.ForEach(e => e.UltCondicao = new DateTime(1800, 12, 28).AddDays(float.Parse(e.UltCondicao)).ToString("dd/MM/yyyy"));

            lista.ForEach(e => e.Unitario = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Unitario, new CultureInfo("en").NumberFormat)));
            lista.ForEach(e => e.Custo = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Custo, new CultureInfo("en").NumberFormat)));
            lista.ForEach(e => e.CustoDiario = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.CustoDiario, new CultureInfo("en").NumberFormat)));

            lista.ForEach(e => e.Total = string.Format(new CultureInfo("pt-BR"), "{0:N}", double.Parse(e.Total, new CultureInfo("en").NumberFormat)));

            lista.ForEach(e => e.DadosItens = "Qtde " +  e.Qtde.ToString() + " " + "Uni. " + e.Unitario.ToString() + " " + "Marg. " + e.MargemAvista.ToString() + 
                          " " + "Custo " + e.Custo.ToString() + " " + "C.Dia " + e.CustoDiario.ToString() + " " + "U.Cond. " + e.UltCondicao.ToString() +
                          " " + "Total " + e.Total.ToString());

            return lista;
        }
    
13.09.2017 / 16:12