Unified description of inelastic and quasielastic electron scattering from nuclei