Optimal investment in multidimensional Markov-modulated affine models