There's more than one way to deal with negative work mates and it depends very much on whether they are a chronic whinger or just going through a bad patch.

I've always had a very 'black and white' approach with chronic whingers: Resign and get a job that makes you happy!  It's that simple.  

You wouldn't eat food you don't like, nor flat with people you detest so why put yourself through a job you hate?

On the other hand, occasionally negative people need a different approach that includes listening, empathy and guidance.  

This article gives you some useful tips on how to deal with both chronic and occasional negativity in the workplace.