Two types of searches in the same textbox

1

I would like to know if you can search two types of variables (one at a time) in a single textbox. Example:

public ActionResult Index(string pesquisa)
{
    var usuario =  from u in db.usuario
                  select u;

    if (!String.IsNullOrEmpty(pesquisa))
    {
        usuario = usuario.Where(p => p.nomecompleto.Contains(pesquisa));
    }

    return View(usuario);
}

This my code above returns the registered users of the site according to the name. I would like the site administrator to have the option to search users both by name and by the CPF (which was set to int ) simply by typing the name or CPF.

Could someone explain if this is possible? And if possible, I'd like to take advantage of the above code.

    
asked by anonymous 04.09.2014 / 04:08

1 answer

2

It is possible. Just make your search string search also for the CPF.

I do not know your User class, but I suppose it has a CPF field which is a String already formatted, and what comes from the screen is also a String of CPF already formatted within the pesquisa field %:

public ActionResult Index(string pesquisa)
{
    var usuario =  from u in db.usuario
                  select u;

    if (!String.IsNullOrEmpty(pesquisa))
    {
        usuario = usuario.FirstOrDefault(p => p.nomecompleto.Contains(pesquisa) || p.cpf.Contains(pesquisa));
    }

    return View(usuario);
}
    
04.09.2014 / 05:20