Difficulty in filtering information

Asked

Viewed 73 times

-1

I know my problem is logical and it must come from me, I know, but sometimes a light, not a code ready, but the pointing of a path helps us a lot.

1) I have 6 Combobox in my View that make the filters for a search.

2) This search should mount some Checkbox’s, based on the past filter. It turns out that this setup of checkboxes, the LINQ that brings the result is my model. Some told me here that pass direct parameter to the Model, breaks the OO paradigm and agree. At this time begins my problem.

3) I’m having trouble doing this. I fill in the parameters in the View and via Jquery I pick them up. Now how do I distribute to my model, so that LINQ runs with these filters being passed in the LINQ or Lambda Where. Below my Model.

public static List<MontaArvoreAcao> montaArvoreAcao( )
        {
            RupturaEntities db = new RupturaEntities();

            var monta_arvore = (from rup in db.Ruptura
                                join ap in db.Apresentacao on rup.Codigo_Apresentacao equals (ap.Codigo_Apresentacao)
                                join mo in db.Motivo on rup.IDMotivo equals (mo.IDMotivo)
                                join pdv in db.PDV on rup.CodigoPDV equals (pdv.CodigoPDV)

                                where rup.IDMotivo != 6

                                //group rup by new { rup.IDRuptura} into gr

                                select new MontaArvoreAcao
                                {
                                    IDRuptura = rup.IDRuptura,
                                    DataRuptura = rup.DataRuptura,
                                    IDMotivo = rup.IDMotivo,
                                    Motivo = rup.Motivo.Motivo1,
                                    IDOrigem = rup.IDOrigem,
                                    CodigoPDV = rup.CodigoPDV,
                                    UF = rup.PDV.UF,
                                    Cidade = pdv.Cidade,
                                    CnpjDescricao = pdv.Cnpj + " - " + pdv.Descricao,
                                    Codigo_Apresentacao = rup.Codigo_Apresentacao,
                                    Unidade_Negocio = ap.Unidade_Negocio,
                                    Codigo_Unidade_Negocio = ap.Codigo_Unidade_Negocio,
                                    Franquia = ap.Franquia,
                                    Familia = ap.Familia,
                                    Descricao = ap.Descricao,
                                    Tipo_Rede = pdv.Tipo_PDV,
                                    Farmacia = pdv.Descricao
                                }).ToList().OrderBy(r => r.IDMotivo);

            return monta_arvore.ToList();
        }

The parameters coming from the View are:

Estado, Cidade, Tipo_PDV, Descricao, UN, Familia de Produto.

I changed my Action to receive parameters as you see it. How I pass the parameters to these arguments?

public ActionResult Acao(string _uf, string _cidade, string _descricao)
        {
            string user = System.Security.Principal.WindowsIdentity.GetCurrent().Name.Split('\\')[1].Trim();

            ViewBag.User = user;

            ViewData["ListaUn"] = MontaArvoreAcao.CriarListaArvoreUn(_uf,_cidade,_descricao);

            ViewData["ListaFamilia"] = MontaArvoreAcao.CriarListaArvoreFamilia();

            ViewData["ListaProd"] = MontaArvoreAcao.CriarListaArvoreProduto();

            ViewData["ListaPdv"] = MontaArvoreAcao.CriarListaArvorePdv();

            return View(MontaArvoreAcao.montaArvoreAcao());
        }
  • 1

    I’ll give you a hint. Try to find a short title that explains very well what the problem is. Often this will only help people become interested in your question. But sometimes it will even make it easier for you to better understand the problem. Yes, it will be hard to think of such a good title. And that’s the secret, it makes you force the brain deeper into the problem. Of course, the ideal is to do it with text. I’m not saying that the overall text is bad but that if you really dive in head first can help you directly.

1 answer

0

I remembered that via jquery I do it. It’s already solved.

Function.....

$.ajax({

    url: '/Controller/Action',

    ......

    data: JSON.stringify({ _uf: $('#cbxUf').val(), _cidade: $('#cbxCidade :selected').text(), _descricao:   $('#cbxDescricao :selected').text() }),

E assim por diante

})

Browser other questions tagged

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