First, have you investigated the cost of repairing or had an expert inspect the foundation? That would be my first move. In order to repair it properly you would probably have to jack up the house. Secondly, if the foundation was done poorly and it's not the ground, what else in the house might not be done properly. Definitely get a home inspection before you buy.