@RequestMapping(value = "doajout", method = RequestMethod.POST) public String doajoutUser(FormAjoutDctap formAjout, BindingResult bindResult, Model model) { model.addAttribute("lesProfs", manager.getAllProf()); model.addAttribute("lesAP", manager.getAllAPForEleve()); formAjout.setAnneeScolaire(UtilSession.getAnneeScolaireInSession()); formAjout.setEleveId(UtilSession.getUserInSession().getId()); formAjout.setEtat(0); if (formAjout.getDate() == null) { bindResult.rejectValue("date", "required", "Une date valide est attendue !"); return "eleve/doajout"; } if (bindResult.hasErrors()) { return "eleve/ajoutdctap"; } else { AccPersonalise acc = new AccPersonalise(null, formAjout.getAccPersNom(), 1, formAjout.getEleveId()); if (manager.getAPById(formAjout.getAccPersId()) != null) { acc = manager.getAPById(formAjout.getAccPersId()); } else { manager.addAP(acc); } DemandeValidationConsoTempsAccPers dctap = new DemandeValidationConsoTempsAccPers( formAjout.getId(), manager.getCurrentAnneeScolaire(), formAjout.getDate(), formAjout.getMinutes(), manager.getUserById(formAjout.getProfId()), acc, manager.getUserById(formAjout.getEleveId()), formAjout.getEtat()); if (dctap.getMinutes() % 10 == 0 && dctap.getMinutes() <= 300 && dctap.getMinutes() != 0) { manager.addDVCTAP(dctap); } else { bindResult.rejectValue("date", "required", "La durée de l'AP est invalide !"); return "eleve/doajout"; } return "redirect:/app/eleve/index"; } }
@RequestMapping(value = "doedit", method = RequestMethod.POST) public String doeditDCTAPById( FormDemandeConsoTempsAccPers formDctap, BindingResult bindResult, Model model) { User prof = manager.getUserById(formDctap.getProfId()); if (prof == null) bindResult.rejectValue("profId", "required", "Erreur d'identifiant de professeur"); if (bindResult.hasErrors()) { model.addAttribute("lesProfs", manager.getAllProf()); return "eleve/edit"; } else { User user = UtilSession.getUserInSession(); DemandeValidationConsoTempsAccPers dctapForUpdate = manager.getDVCTAPById(Long.valueOf(formDctap.getId())); if (dctapForUpdate.getEtat() == 0 || dctapForUpdate.getEtat() == 4) { AccPersonalise acc = new AccPersonalise(null, formDctap.getAccPersNom(), 1, user.getId()); if (manager.getAPById(formDctap.getAccPersId()) != null) { acc = manager.getAPById(formDctap.getAccPersId()); dctapForUpdate.setAccPers(manager.getAPById(formDctap.getAccPersId())); } else { manager.addAP(acc); dctapForUpdate.setAccPers(manager.getAPByNom(formDctap.getAccPersNom())); } dctapForUpdate.setDateAction(formDctap.getDateAction()); dctapForUpdate.setMinutes(formDctap.getMinutes()); dctapForUpdate.setProf(manager.getUserById(formDctap.getProfId())); dctapForUpdate.setDctapModifEleve(); manager.updateDVCTAP(dctapForUpdate); } return "redirect:/app/eleve/mesdctap"; } }