Example #1
0
        public override Hotel getById(int id)
        {
            RepositorioCategoria      repositorioCategoria      = new RepositorioCategoria();
            RepositorioRegimen        repositorioRegimen        = new RepositorioRegimen();
            RepositorioCierreTemporal repositorioCierreTemporal = new RepositorioCierreTemporal();
            RepositorioDireccion      repositorioDireccion      = new RepositorioDireccion();
            RepositorioReserva        repositorioReserva        = new RepositorioReserva();

            String        connectionString = ConfigurationManager.AppSettings["BaseLocal"];
            SqlConnection sqlConnection    = new SqlConnection(connectionString);
            SqlCommand    sqlCommand       = new SqlCommand();
            SqlDataReader reader;
            Hotel         hotel = null;

            sqlCommand.Parameters.AddWithValue("@idHotel", id);
            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.Connection  = sqlConnection;
            sqlCommand.CommandText = "SELECT * FROM LOS_BORBOTONES.Hotel WHERE idHotel = @idHotel";

            sqlConnection.Open();

            reader = sqlCommand.ExecuteReader();

            if (reader.Read())
            {
                int      idHotel     = reader.GetInt32(reader.GetOrdinal("idHotel"));
                String   nombre      = reader.GetString(reader.GetOrdinal("Nombre"));
                String   mail        = reader.SafeGetString(reader.GetOrdinal("Mail"));
                String   telefono    = reader.SafeGetString(reader.GetOrdinal("Telefono"));
                DateTime fechaInicio = reader.GetDateTime(reader.GetOrdinal("FechaInicioActividades"));
                int      idCategoria = reader.GetInt32(reader.GetOrdinal("idCategoria"));
                int      idDireccion = reader.GetInt32(reader.GetOrdinal("idDireccion"));

                Categoria categoria = repositorioCategoria.getById(idCategoria);

                Direccion direccion = repositorioDireccion.getById(idDireccion);



                hotel = new Hotel(idHotel, categoria, direccion, nombre, mail, telefono, fechaInicio);
            }
            else
            {
                //Si no encuentro elemento con ese ID tiro una excepción
                throw new NoExisteIDException("No existe hotel con el ID asociado");
            }

            //Cierro Primera Consulta
            sqlConnection.Close();

            return(hotel);
        }
Example #2
0
        public override List <Hotel> getAll()
        {
            RepositorioCategoria      repositorioCategoria      = new RepositorioCategoria();
            RepositorioRegimen        repositorioRegimen        = new RepositorioRegimen();
            RepositorioCierreTemporal repositorioCierreTemporal = new RepositorioCierreTemporal();
            RepositorioDireccion      repositorioDireccion      = new RepositorioDireccion();
            RepositorioReserva        repositorioReserva        = new RepositorioReserva();

            List <Hotel>  hoteles          = new List <Hotel>();
            String        connectionString = ConfigurationManager.AppSettings["BaseLocal"];
            SqlConnection sqlConnection    = new SqlConnection(connectionString);
            SqlCommand    sqlCommand       = new SqlCommand();
            SqlDataReader reader;
            Hotel         hotel = null;

            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.Connection  = sqlConnection;
            sqlCommand.CommandText =
                "SELECT idHotel,Nombre,Mail,Telefono,FechaInicioActividades,idCategoria,idDireccion FROM LOS_BORBOTONES.Hotel AS HOT;";

            sqlConnection.Open();

            reader = sqlCommand.ExecuteReader();

            while (reader.Read())
            {
                int      idHotel     = reader.GetInt32(reader.GetOrdinal("idHotel"));
                String   nombre      = reader.GetString(reader.GetOrdinal("Nombre"));
                String   mail        = reader.SafeGetString(reader.GetOrdinal("Mail"));
                String   telefono    = reader.SafeGetString(reader.GetOrdinal("Telefono"));
                DateTime fechaInicio = reader.GetDateTime(reader.GetOrdinal("FechaInicioActividades"));
                int      idCategoria = reader.GetInt32(reader.GetOrdinal("idCategoria"));
                int      idDireccion = reader.GetInt32(reader.GetOrdinal("idDireccion"));

                Categoria categoria = repositorioCategoria.getById(idCategoria);

                Direccion direccion = repositorioDireccion.getById(idDireccion);

                hotel = new Hotel(idHotel, categoria, direccion, nombre, mail, telefono,
                                  fechaInicio);
                hoteles.Add(hotel);
            }

            //Cierro Primera Consulta
            sqlConnection.Close();


            return(hoteles);
        }
Example #3
0
        public List <Hotel> getByQuery(String nombreHotel, int?estrellas, String ciudad, String pais)
        {
            RepositorioCategoria      repositorioCategoria      = new RepositorioCategoria();
            RepositorioRegimen        repositorioRegimen        = new RepositorioRegimen();
            RepositorioCierreTemporal repositorioCierreTemporal = new RepositorioCierreTemporal();
            RepositorioDireccion      repositorioDireccion      = new RepositorioDireccion();
            RepositorioReserva        repositorioReserva        = new RepositorioReserva();

            List <Hotel>  hoteles          = new List <Hotel>();
            String        connectionString = ConfigurationManager.AppSettings["BaseLocal"];
            SqlConnection sqlConnection    = new SqlConnection(connectionString);
            SqlCommand    sqlCommand       = new SqlCommand();
            SqlDataReader reader;

            sqlCommand.CommandType = CommandType.Text;
            sqlCommand.Connection  = sqlConnection;
            sqlCommand.CommandText =
                "SELECT DISTINCT(HOT.idHotel),HOT.Nombre,HOT.Mail,HOT.Telefono,HOT.FechaInicioActividades,HOT.idCategoria,HOT.idDireccion FROM LOS_BORBOTONES.Hotel AS HOT" +
                " JOIN LOS_BORBOTONES.Categoria AS CAT ON CAT.idCategoria= HOT.idCategoria" +
                " JOIN LOS_BORBOTONES.Direccion AS DIR ON DIR.idDireccion = HOT.idDireccion" + getCondiciones(nombreHotel, estrellas, ciudad, pais, sqlCommand) + ";";

            sqlConnection.Open();

            reader = sqlCommand.ExecuteReader();

            while (reader.Read())
            {
                int      idHotel     = reader.GetInt32(reader.GetOrdinal("idHotel"));
                String   nombre      = reader.GetString(reader.GetOrdinal("Nombre"));
                String   mail        = reader.SafeGetString(reader.GetOrdinal("Mail"));
                String   telefono    = reader.SafeGetString(reader.GetOrdinal("Telefono"));
                DateTime fechaInicio = reader.GetDateTime(reader.GetOrdinal("FechaInicioActividades"));
                int      idCategoria = reader.GetInt32(reader.GetOrdinal("idCategoria"));
                int      idDireccion = reader.GetInt32(reader.GetOrdinal("idDireccion"));

                Categoria categoria = repositorioCategoria.getById(idCategoria);

                Direccion direccion = repositorioDireccion.getById(idDireccion);

                Hotel hotel = new Hotel(idHotel, categoria, direccion, nombre, mail, telefono, fechaInicio);
                hoteles.Add(hotel);
            }

            //Cierro Primera Consulta
            sqlConnection.Close();
            return(hoteles);
        }