private void btnBuscar_Click(object sender, System.EventArgs e) { try { var contatos = _contatoController.GetAll(); if (!string.IsNullOrEmpty(tbNome.Text)) { contatos = contatos.Where(p => p.Nome.Contains(tbNome.Text)); tblContatos.DataSource = new BindingList <ContatoEntity>(contatos.OrderBy(p => p.Nome).ToList()); } if (!string.IsNullOrEmpty(tbTelefone.Text)) { var contatosPorTelefone = _contatoController.SelectByNumero(tbTelefone.Text); if (contatosPorTelefone != null) { var idsContatos = contatosPorTelefone.ToList().Select(p => p.Id); contatos = contatos.Where(p => idsContatos.Contains(p.Id)); tblContatos.DataSource = new BindingList <ContatoEntity>(contatos.OrderBy(p => p.Nome).ToList()); } } if (contatos.Count() <= 0) { MessageBox.Show("A busca não retornou resultados."); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }