I can’t see which argument I should use to do this job

Asked

Viewed 66 times

0

public class RetornoBO
{
    List<RetornoRomaneioPostagem> OK = new List<RetornoRomaneioPostagem>();
    Dictionary<string, int> retorno = new Dictionary<string, int>();
    Dictionary<string, int> baixas = new Dictionary<string, int>();

    public void RetornarPorImgBO(int idEmpresa, List<String> lista)
    {
        try
        {
            for (int i = 0; i < lista.Count(); i++)
            {
                var nomeImag = ValidarNomeImag(lista[i]);

                if (nomeImag != null)
                {
                    if (BaixadoNRetornado.Any(b => b.Numero_Auto == nomeImag.Numero_Auto && b.Tipo_Notificacao == nomeImag.Tipo_Notificacao))
                    {
                     OK.Add(?);
                    }
                    else
                    {
                        retorno.Add(?);
                    }
                }
            }
        }

        catch (Exception ex)
        {
            clog.ArquivoLog("ImportarArquivo()", ex);
            throw ex;
        }
    }

    private RetornoRomaneioPostagem ValidarNomeImag(String arquivo)
    {
        try
        {
            if (arquivo.Length == 16)
            {
                var retorno = new RetornoRomaneioPostagem();

                retorno.Tipo_Notificacao = Convert.ToInt32(arquivo.Substring(10, 1));
                retorno.Numero_Auto = String.Format("D{0}", arquivo.Substring(1, 9));

                return retorno;
            }
            else
            {
                return null;
            }
        }
        catch (Exception ex)
        {
            clog.ArquivoLog("ImportarArquivo()", ex);
            throw ex;
        }
    }

    private List<RetornoRomaneioPostagem> BaixadoNRetornado(List<RetornoRomaneioPostagem> baixasNRetornadas)
    {
        try
        {
            List<RetornoRomaneioPostagem> nRetorndasBaixadas = new List<RetornoRomaneioPostagem>();

            var retornoRPostagem = new RetornoRomaneioPostagem();

            if (baixasNRetornadas.Where(b => b.Numero_Auto == retornoRPostagem.Numero_Auto && b.Tipo_Notificacao == retornoRPostagem.Tipo_Notificacao).Any())
            {
                nRetorndasBaixadas.Add(retornoRPostagem);

                return nRetorndasBaixadas;
            }
            else
            {
                return null;
            }
        }
        catch (Exception ex)
        {
            clog.ArquivoLog("ImportarArquivo()", ex);
            throw ex;
        }
    }

    private List<RetornoRomaneioPostagem> NBaixaCRomaneio(List<RetornoRomaneioPostagem> nBaixaCRomaneio)
    {
        try
        {
            List<RetornoRomaneioPostagem> cRomaneioNBaixadas = new List<RetornoRomaneioPostagem>();

            var retornoRPost = new RetornoRomaneioPostagem();

            if (nBaixaCRomaneio.Where(c => c.Numero_Auto == retornoRPost.Numero_Auto && c.Tipo_Notificacao == retornoRPost.Tipo_Notificacao).Count() == 0)
            {
                cRomaneioNBaixadas.Add(retornoRPost);

                return cRomaneioNBaixadas;
            }
            else
            {
                return null;
            }
        }
        catch (Exception ex)
        {
            clog.ArquivoLog("ImportarArquivo()", ex);
            throw ex;
        }
    }
}

}

  • 5

    And what is your question? See http://answall.com/help/how-to-ask

  • 1

    What’s the problem? In addition to capturing a generic exception and relaunching the exception?

  • I can’t see it either, but I’d say it’s not viable.

  • 1

    I need to do an if for Downloadsnreturned within the existing if, but I’m not getting it. So I tried to make a variable but this asking for an argument that I can’t put

  • From the looks of it, he’s expecting a List<RetornoRomaneioPostagem>. Create a list of this or take it from somewhere in your code, if any.

  • But we need to know where the bug is and what it is. Without relevant information you have no way to respond. I’m going to guess a possibility, change the if for: (baixasNRetornadas.Any(b => b.Numero_Auto == retornoRPostagem.Numero_Auto && b.Tipo_Notificacao == retornoRPostagem.Tipo_Notificacao)

  • 1

    All things I’ve tried from with invalid argument or that method does not exist in context.

  • If you do not pass complete information about the mistake, no one will be able to help. There is no way we can guess the problem without a complete description of it. Copy and paste into the question what is presented. If you show a line number, let us know which lines in your code match this line so we can identify better. Remember that we are not seeing the same as you in your VS.

  • What I want to do is check if the numero_auto and the notification typeImag exist inside the downloaded

  • Amanda, edit your question by putting only the method in which the error occurs. There are several IF’s in your question, there is no clear way to know which one you are referring to.

Show 5 more comments

1 answer

1

If I understood the problem the solution would be this:

private List<RetornoRomaneioPostagem> BaixadoNRetornado(List<RetornoRomaneioPostagem> baixasNRetornadas) {
    try {
        var nRetorndasBaixadas = new List<RetornoRomaneioPostagem>();
        var retornoRPostagem = new RetornoRomaneioPostagem();
        if (baixasNRetornadas.Any(b => b.Numero_Auto == retornoRPostagem.Numero_Auto && b.Tipo_Notificacao == retornoRPostagem.Tipo_Notificacao)) {
            nRetorndasBaixadas.Add(retornoRPostagem);
            return nRetorndasBaixadas;
        } else {
            return null;
        }
    } catch (Exception ex) {
        clog.ArquivoLog("Alguma informação relevante aqui, não qualquer coisa", ex);
        throw;
    }
}

I put in the Github for future reference.

I have serious doubts whether I should do the code like this, it doesn’t seem to make sense. The two methods seem to do unnecessary things.

Note that in addition to the problem that was in the code I improved the treatment of the exception. I have my doubts as to whether this treatment should be there, but I cannot say anything without seeing the full application. I recommend rethinking how you handle the exceptions. There are several answers from me at website talking about this.

If there is more problem, mainly of logic has no way of knowing without having more details.

At least this helped before the question was edited. I could help more if I knew what and where exactly the error is but I could not get this information despite numerous attempts.

Browser other questions tagged

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