We present an approach for calculating near-edge X-ray absorption spectra at the density functional theory level, which is suited for condensed matter simulations. The method is based on the standard solution of the all-electron KS equations with a modified core-hole potential, which reproduces the relaxation of the orbitals induced by the promotion of the core electron to an unoccupied valence level. The all-electron description of the charge density is based on the Gaussian and augmented plane wave formalism. The reliability of the proposed method is assessed by comparing the computed spectra of some small molecules in the gas phase to the experimental spectra reported in literature. The sensitivity of the computed spectra to the local environment, i.e. the specific bonds formed by the absorbing atom or the presence of hydrogen bonds, open promising perspective for this technique as a predictive tool in the investigation of a more complex system of an unknown structure. The straightforward extension of the method to condensed matter is demonstrated by the calculation of the C K-edge in diamond.