"...God is working everything together for the good of those who love Him, even those things we think are bad. A sizable number of the difficult situations we experience are our own fault, and many others are due to the fact that we live in an evil world. But God will work even those situations in our favor if we let Him."
Please read Did God Put Joseph in Bad Situations?, by Jack Kelley, at Grace Thru Faith.
And we know that God causes all things to work together for good to those who love God, to those who are called according to His purpose.