private PersonaFiltro BuilFiltroPersona() { string cedula = HttpContext.Request.Query["cedula"].ToString(); string nombre = HttpContext.Request.Query["nombre"].ToString(); string correo = HttpContext.Request.Query["correo"].ToString(); string cargo = HttpContext.Request.Query["cargo"].ToString(); string sexoStr = HttpContext.Request.Query["sexo"].ToString(); int IdSexo = sexoStr.TrueInt(); cedula = (cedula.EsNulaOVacia()) ? string.Empty : cedula.Trim(); nombre = (nombre.EsNulaOVacia()) ? string.Empty : nombre.Trim(); correo = (correo.EsNulaOVacia()) ? string.Empty : correo.Trim(); cargo = (cargo.EsNulaOVacia()) ? string.Empty : cargo.Trim(); PersonaFiltro filtro = new PersonaFiltro(); filtro.cedula = cedula; filtro.nombre = nombre; filtro.correo = correo; filtro.cargo = cargo; filtro.sexo = IdSexo; return(filtro); }
//------------------------------------ public async Task <IEnumerable <PersonaVM> > GetAllVM(PersonaFiltro filtro) { int icedula = (filtro.cedula.EsNulaOVacia()) ? 0 : 1; int inombre = (filtro.nombre.EsNulaOVacia()) ? 0 : 1; int icorreo = (filtro.correo.EsNulaOVacia()) ? 0 : 1; int icargo = (filtro.cargo.EsNulaOVacia()) ? 0 : 1; int isexo = (filtro.sexo > 0) ? 1 : 0; if (icedula == 1) { filtro.cedula = filtro.cedula.Trim().ToLower(); } if (inombre == 1) { filtro.nombre = filtro.nombre.Trim().ToLower(); } if (icorreo == 1) { filtro.correo = filtro.correo.Trim().ToLower(); } if (icargo == 1) { filtro.cargo = filtro.cargo.Trim().ToLower(); } var todos = await _context.Personas .Include(i => i.sexo6) .Where(w => ((icedula == 0) || (w.cedula.ToLower().Contains(filtro.cedula))) && ((inombre == 0) || (w.nombre_comp.ToLower().Contains(filtro.nombre))) && ((icorreo == 0) || (w.email.ToLower().Contains(filtro.correo))) && ((icargo == 0) || (w.cargo.ToLower().Contains(filtro.cargo))) && ((isexo == 0) || (w.sexo_6_id == filtro.sexo)) ) .OrderBy(o => o.nombre1) .Select(s => new PersonaVM { persona_id = s.persona_id, cedula = s.cedula, nombre1 = s.nombre1, nombre2 = s.nombre2, apellido1 = s.apellido1, apellido2 = s.apellido2, nombre_comp = s.nombre_comp, tlf_movil = s.tlf_movil, tlf_local = s.tlf_local, email = s.email, cargo = s.cargo, sexo_6_id = s.sexo_6_id, sexo6 = s.sexo6.descripcion }) .ToListAsync(); return(todos); }
public async Task <IEnumerable <PersonaVM> > GetAllVM() { //throw new Exception(); //Console.WriteLine("Entro"); PersonaFiltro filtro = BuilFiltroPersona(); var personas = await _servicioPersona.GetAllVM(filtro); return(personas); }
//------------------------------------ public async Task <IEnumerable <Persona> > GetAll(PersonaFiltro filtro) { int icedula = (filtro.cedula.EsNulaOVacia()) ? 0 : 1; int inombre = (filtro.nombre.EsNulaOVacia()) ? 0 : 1; int icorreo = (filtro.correo.EsNulaOVacia()) ? 0 : 1; int icargo = (filtro.cargo.EsNulaOVacia()) ? 0 : 1; int isexo = (filtro.sexo > 0) ? 0 : 1; if (icedula == 1) { filtro.cedula = filtro.cedula.Trim().ToLower(); } if (inombre == 1) { filtro.nombre = filtro.nombre.Trim().ToLower(); } if (icorreo == 1) { filtro.correo = filtro.correo.Trim().ToLower(); } if (icargo == 1) { filtro.cargo = filtro.cargo.Trim().ToLower(); } var todos = await _context.Personas .Where(w => ((icedula == 0) || (w.cedula.ToLower().Contains(filtro.cedula))) && ((inombre == 0) || (w.nombre_comp.ToLower().Contains(filtro.nombre))) && ((icorreo == 0) || (w.email.ToLower().Contains(filtro.correo))) && ((icargo == 0) || (w.cargo.ToLower().Contains(filtro.cargo))) && ((isexo == 0) || (w.sexo_6_id == filtro.sexo)) ).OrderBy(o => o.nombre1) .ToListAsync(); return(todos); }