Affine modeling of credit risk, pricing of credit events, and contagion