Exit from my service does not match my dto

Asked

Viewed 51 times

1

On my way out of service to the Dadositens camp, 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>

Turns out I don’t have any Qtde Label or Cost or Margin or any other in my DTO which is what I export for the service. I tried yes, to put this Labels, but as it was giving error, not on the label, but the way I was doing, I removed them and left only the fields. And after I got it all right, I went to spin and it’s coming like this and I don’t know where it’s fixed (the first time) to fix it, because I can’t go up like this, because I don’t know what’s going on. This concatenation I did, because I need to play in a cell of my Xamarin App.Forms these fields all together in the same cell, because the client wants it this way and was not able to do it in the App and the Xamarin forum, they 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;
        }
    }

Note that I have no label or name of the fields. As I said I had done so the first time, but it did not run, I was with errors. First I removed them thinking it was them and then I saw that it had to do with the bank, then I left them without them and now it’s coming like this. How do I do it? Restart the PC, rs?

EDIT1

Every time I clean up on Solution, I get in trouble. Solved with clean, the problem of "Labels", but it is giving error in this line and in all that have similar Lambdas, ie all foreach in the class Itensliberacao. 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. Personal, it was working before the clean and I don’t know what else is going on, honestly. If I comment on all the foreach in the itensLiberacao class, then the service goes up and without the "Labels". Restart VS and still persist error:

Input string was not in a correct format.

On my website is working with this foreach, I just haven’t gone up with these 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 the return of the service 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>

Dadositens is commented on, both in the DTO as in the service class

I don’t know where this is coming from, if I’ve commented on this field in both DTO and service class:

<DadosItens>3 46,66 68,58 0 30/01/2017 46,66 205,73</DadosItens>
  • The error may be due to the new Dadositens field, but it already worked, as I indicated in the post and now nothing works. Possibly some string, the transformation is giving way, but does anyone know how I solve it? As far as I know ToString()guarantees nothing.

  • The CLEAN command cleans the previous packages that were created in your build, the fault is not clean, but some change you made between the command call. This error is incorrect formatting on that part float.Parse(e.UltCondicao), if he can’t do the parse this exception happens.

  • @Gabrielcoletta, but before I created the Dadositens Press, it was working with this parse and if I comment on the foreach, it works too and if I comment on the Dadositens and I leave the foreach uncommented, it also works. Just not working, with both enabled.

  • I recommend that you break this lambda in the normal foreach and go debugging this expression, this very unreadable and do not know exactly where this exception happens, it can happen in this Tostring too.

  • Commented and still coming data from him? This behavior is very strange, when you say "I raise the service", you say publish the app?

  • When I go up the service, I get Postman or Browser(xml)

  • @Gabrielcoletta, the following gave a clean on Solution and forgot to comment only on me DTO the field Dadositens. When I went up the service, came the field with nil, ok normal. I commented and when I went up, it kept coming. Only when I cleaned Solution did it stop appearing in Postman or Chrome(xml). It seems to be some sort of cache in the application, the bad thing is that I will always have to be doing Clean in the Solution.

Show 2 more comments

1 answer

0

I didn’t understand, but suddenly it worked. I gave some cleans. The colleague Gabriel Colleta, told me that nothing to do with Clean, but after giving some (some 3), it worked. So was my code: 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 that exports 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;
        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.