Finite and affine W-algebras and their applications