private Viaje MapearViaje(DataTable data_table) { try { Automovil automovil_mapper = new Automovil(); Chofer chofer_mapper = new Chofer(); Turno turno_mapper = new Turno(); Cliente cliente_mapper = new Cliente(); foreach (DataRow row in data_table.Rows) { return(new Viaje { id = Convert.ToInt32(row.ItemArray[0]), automovil = automovil_mapper.Mapear(Convert.ToInt32(row.ItemArray[1])), chofer = chofer_mapper.Mapear(Convert.ToInt32(row.ItemArray[2])), turno = turno_mapper.Mapear(Convert.ToInt32(row.ItemArray[3])), cantidad_kilometros = Convert.ToInt32(row.ItemArray[4]), fecha_inicio = Convert.ToDateTime(row.ItemArray[5]), fecha_fin = Convert.ToDateTime(row.ItemArray[6]), cliente = cliente_mapper.Mapear(Convert.ToInt32(row.ItemArray[7])) }); } throw new Exception("Hubo un error al mapear el viaje"); } catch (Exception exception) { throw new Exception(exception.Message); } }
public List <Automovil> ObtenerAutomoviles() { try { List <Automovil> automoviles = new List <Automovil>(); Conexion conexion = new Conexion(); SqlCommand store_procedure = conexion.IniciarStoreProcedure("sp_obtener_automoviles"); DataTable respuesta_consulta = conexion.EjecutarConsultar(store_procedure); Automovil automovil_mapper = new Automovil(); foreach (DataRow row in respuesta_consulta.Rows) { automoviles.Add(automovil_mapper.Mapear(Convert.ToInt32(row.ItemArray[0]))); } return(automoviles); } catch (Exception exception) { throw new Exception(exception.Message); } }