First-principle calculation for the core level shifts of clean and covered surfaces