public ICollection <AeropuertoTo> ObtenerAeropuertosPorFiltro(FiltroGeograficoTo filtro) { List <AeropuertoTo> aeropuertos = new List <AeropuertoTo>(); using (var Contexto = ViveVolarDbContext.GetDbContext()) { var aeropuertoRepositorio = new AeropuertoRepository(Contexto); var result = aeropuertoRepositorio.Filtrar(ConstruirExpresionConsultaAeropuertoPorFiltroGeografico(filtro)).ToList(); aeropuertos = Mapper.Map <List <AeropuertoTo> >(result); } return(aeropuertos); }
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); }