public ICollection <AeropuertoTo> ObtenerAeropuertosPorFiltro(FiltroAeropuertoTo filtro) { List <AeropuertoTo> aeropuertos = new List <AeropuertoTo>(); using (var Contexto = ViveVolarDbContext.GetDbContext()) { var aeropuertoRepositorio = new AeropuertoRepository(Contexto); var expressionFilter = ConstruirExpresionConsultaAeropuertoPorFiltroAeropuerto(filtro); if (expressionFilter != null) { var result = aeropuertoRepositorio.Filtrar(expressionFilter).ToList(); aeropuertos = Mapper.Map <List <AeropuertoTo> >(result); } else { Expression <Func <OrigenDestino, bool> > filtroInfo = null; var origenDestinoRepositorio = new OrigenDestinoRepository(Contexto); if (filtro.CriterioOrigenDestino == EsOrigenODestino.EsDestino) { filtroInfo = o => o.Id == int.Parse(filtro.Id) && o.EsDestino == "S"; } else if (filtro.CriterioOrigenDestino == EsOrigenODestino.EsOrigen) { filtroInfo = o => o.Id == int.Parse(filtro.Id) && o.EsDestino == "S"; } else { filtroInfo = o => o.Id == int.Parse(filtro.Id); } var result = origenDestinoRepositorio.Filtrar(filtroInfo).Select(a => a.Aeropuerto).ToList(); aeropuertos = Mapper.Map <List <AeropuertoTo> >(result); } } return(aeropuertos); }
public Expression <Func <Aeropuerto, bool> > ConstruirExpresionConsultaAeropuertoPorFiltroAeropuerto(FiltroAeropuertoTo filtro) { Expression <Func <Aeropuerto, bool> > filtroInfo = null; switch (filtro.IdFiltroBusqueda) { case FiltroAeropuerto.IdAeropuerto: filtroInfo = a => a.Id == int.Parse(filtro.Id); break; case FiltroAeropuerto.CodMundial: filtroInfo = a => a.CodigoMundial == filtro.Id; break; } return(filtroInfo); }