A model of coexistence of antiferromagnetism and superconductivity in electron- and hole-doped cuprates