1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
@Override
public String ajouterUtilisateur(UtilisateurModel pvUtilisateur, int idCompte) {
Session session = HibernateUtils.openSession();
Transaction tx = null;
try {
tx = session.beginTransaction();
int id = 0;
id = (int) session.save(pvUtilisateur);
UtilisateurModel userCompte = UtilisateurBO.findUtilisateurById(idCompte);
Date dateSystem = new Date();
DateFormat shortDateFormat = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT);
String date = shortDateFormat.format(dateSystem);
String detail = "L'utilisateur qui a l'id "+idCompte+" et le login "+userCompte.getLogin()+" a ajouté l'utilisateur qui a l'id "+id
+" et le login "+pvUtilisateur.getLogin()+" le "+date+" ";
HistoriqueUtilisateurModel historiqueUtilisateur = new HistoriqueUtilisateurModel(userCompte, pvUtilisateur, "Ajout", dateSystem, detail);
long idHistorique = (long) session.save(historiqueUtilisateur);
tx.commit();
if(id != 0 && idHistorique != 0){
return "SUCCESS";
}
else{
return "ERROR";
}
} catch (Exception e) {
if (tx != null) {
tx.rollback();
}
System.out.println("exeption ======= "+e.toString());
return "ERROR";
}
finally{
session.close();
}
} |
Partager