Esempio n. 1
0
        public override void update(Hotel hotel)
        {
            if (this.exists(hotel))
            {
                String        connectionString = ConfigurationManager.AppSettings["BaseLocal"];
                SqlConnection sqlConnection    = new SqlConnection(connectionString);
                SqlCommand    sqlCommand       = new SqlCommand();
                SqlDataReader reader;

                Direccion direccion = hotel.getDireccion();
                Categoria categoria = hotel.getCategoria();

                //HOTEL
                sqlCommand.Parameters.AddWithValue("@hotidHotel", hotel.getIdHotel());
                sqlCommand.Parameters.AddWithValue("@hotnombre", hotel.Nombre);
                sqlCommand.Parameters.AddWithValue("@hotmail", hotel.Mail);
                sqlCommand.Parameters.AddWithValue("@hottelefono", hotel.Telefono);
                sqlCommand.Parameters.AddWithValue("@hotfechaInicioActividades", hotel.FechaInicioActividades);

                //DIRECCION
                sqlCommand.Parameters.AddWithValue("@dirpais", direccion.Pais);
                sqlCommand.Parameters.AddWithValue("@dirciudad", direccion.Ciudad);
                sqlCommand.Parameters.AddWithValue("@dircalle", direccion.Calle);
                sqlCommand.Parameters.AddWithValue("@dirnumeroCalle", direccion.NumeroCalle);
                sqlCommand.Parameters.AddWithValue("@dirpiso", direccion.Piso);
                sqlCommand.Parameters.AddWithValue("@dirdepartamento", direccion.Departamento);
                sqlCommand.Parameters.AddWithValue("@idDireccion", direccion.getIdDireccion());

                //CATEGORIA
                sqlCommand.Parameters.AddWithValue("@catId", categoria.getIdCategoria());

                sqlCommand.CommandType = CommandType.Text;
                sqlCommand.Connection  = sqlConnection;
                sqlCommand.CommandText =
                    "BEGIN TRANSACTION " +
                    "DELETE FROM LOS_BORBOTONES.Regimen_X_Hotel WHERE idHotel=@hotidHotel; " +
                    insertsRegimenes(hotel, sqlCommand) +
                    "UPDATE LOS_BORBOTONES.Direccion " +
                    "SET Pais= @dirpais,Ciudad= @dirciudad, Calle=@dircalle, NumeroCalle= @dirnumeroCalle, " +
                    "Piso=@dirpiso, Depto=@dirdepartamento WHERE idDireccion=@idDireccion; " +

                    "UPDATE LOS_BORBOTONES.Hotel " +
                    "SET Nombre= @hotnombre, Mail= @hotmail, Telefono= @hottelefono, FechaInicioActividades= @hotfechaInicioActividades, " +
                    "idCategoria=@catId " +
                    "WHERE idHotel= @hotidHotel; " +
                    "COMMIT";

                sqlConnection.Open();
                reader = sqlCommand.ExecuteReader();
                //Checkear excepcion si no existe u ocurrio algun problema con el update

                //Cierro Primera Consulta
                sqlConnection.Close();
            }
            else
            {
                //throw new RequestInvalidoException("No es posible actualizar: No existe el hotel con id " + hotel.getIdHotel() + "en la base de datos");
                throw new NoExisteIDException("No existe el Hotel que intenta actualizar");
            }
        }