public Cliente getClienteByIdReserva(Reserva reserva) { Cliente cliente = null; String connectionString = ConfigurationManager.AppSettings["BaseLocal"]; SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader reader; sqlCommand.Parameters.AddWithValue("@idReserva", reserva.getIdReserva()); sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = "SELECT idCliente FROM LOS_BORBOTONES.Reserva WHERE idReserva = @idReserva"; sqlConnection.Open(); reader = sqlCommand.ExecuteReader(); if (reader.Read()) { int idCliente = reader.GetInt32(reader.GetOrdinal("idCliente")); RepositorioCliente repoCliente = new RepositorioCliente(); cliente = repoCliente.getById(idCliente); } sqlConnection.Close(); return(cliente); }
public Reserva getIdByIdEstadia(int idEstadia) { Reserva reserva = null; RepositorioRegimen repoRegimen = new RepositorioRegimen(); RepositorioHotel repoHotel = new RepositorioHotel(); RepositorioEstadia repoEstadia = new RepositorioEstadia(); RepositorioCliente repoClientes = new RepositorioCliente(); RepositorioEstadoReserva repoEstadoReserva = new RepositorioEstadoReserva(); String connectionString = ConfigurationManager.AppSettings["BaseLocal"]; SqlConnection sqlConnection = new SqlConnection(connectionString); SqlCommand sqlCommand = new SqlCommand(); SqlDataReader reader; sqlCommand.Parameters.AddWithValue("@idEstadia", idEstadia); sqlCommand.CommandType = CommandType.Text; sqlCommand.Connection = sqlConnection; sqlCommand.CommandText = "SELECT * FROM LOS_BORBOTONES.Reserva WHERE idEstadia = @idEstadia"; sqlConnection.Open(); reader = sqlCommand.ExecuteReader(); while (reader.Read()) { int idReserva = reader.GetInt32(reader.GetOrdinal("idReserva")); decimal codigoReserva = reader.GetDecimal(reader.GetOrdinal("CodigoReserva")); decimal diasAlojados = reader.GetDecimal(reader.GetOrdinal("DiasAlojados")); DateTime fechaDesde = reader.SafeGetDateTime(reader.GetOrdinal("FechaDesde")); DateTime fechaHasta = reader.SafeGetDateTime(reader.GetOrdinal("FechaHasta")); DateTime fechaCreacion = reader.SafeGetDateTime(reader.GetOrdinal("FechaCreacion")); Hotel hotel = repoHotel.getById(reader.GetInt32(reader.GetOrdinal("idHotel")));; Regimen regimen = repoRegimen.getById(reader.GetInt32(reader.GetOrdinal("idRegimen"))); Estadia estadia = repoEstadia.getById(reader.GetInt32(reader.GetOrdinal("idEstadia"))); Cliente cliente = repoClientes.getById(reader.GetInt32(reader.GetOrdinal("idCliente"))); EstadoReserva estado = repoEstadoReserva.getByIdReserva(idReserva); reserva = new Reserva(idReserva, hotel, estadia, regimen, cliente, codigoReserva, diasAlojados, fechaCreacion, fechaDesde, fechaHasta, estado); } sqlConnection.Close(); return(reserva); }