public void ExecutarFiltro() { if (pesquisaNome == null) { pesquisaNome = ""; } var resultado = FiltroUsuarios.Where(n => n.Nome.ToLowerInvariant() .Contains(PesquisaNome.ToLowerInvariant().Trim())).ToList(); var removerDaLista = Usuarios.Except(resultado).ToList(); foreach (var item in removerDaLista) { Usuarios.Remove(item); } for (int index = 0; index < resultado.Count; index++) { var item = resultado[index]; if (index + 1 > Usuarios.Count || !Usuarios[index].Equals(item)) { Usuarios.Insert(index, item); } } }
public List <Usuario> BuscaPorFiltro(FiltroUsuarios filtro) { if (!string.IsNullOrEmpty(filtro.Nome) || !string.IsNullOrEmpty(filtro.UserName)) { return(GetList(RetornaFuncUsuario(filtro)).ToList()); } else { return(GetALL().ToList()); } }
private Func <Usuario, bool> RetornaFuncUsuario(FiltroUsuarios filtro) { if (!string.IsNullOrEmpty(filtro.Nome) && !string.IsNullOrEmpty(filtro.Nome)) { return(usu => usu.Nome.Contains(filtro.Nome) && usu.UserName.Contains(filtro.UserName.ToLower())); } if (!string.IsNullOrEmpty(filtro.Nome)) { return(usu => usu.Nome.Contains(filtro.Nome)); } if (!string.IsNullOrEmpty(filtro.UserName)) { return(usu => usu.UserName.Contains(filtro.UserName.ToLower())); } return(null); }
// GET: CadastroUsuario public ActionResult ListaUsuarios(FormCollection form) { var nome = form["nome"]; var userName = form["userName"]; var filtro = new FiltroUsuarios() { Nome = nome, UserName = userName }; var usuarios = _usuarioRepository.BuscaPorFiltro(filtro); ViewBag.Filtro = filtro; var userStore = new UserStore <IdentityUser>(new ModeloIdentityDbContext()); var userManager = new UserManager <IdentityUser>(userStore); var x = new ModeloIdentityDbContext().Users.ToList(); ShowToast(); return(View(Mapper.Map <IEnumerable <Usuario>, IEnumerable <UsuarioViewModel> >(usuarios))); }