if (form.hasErrors()) {
return badRequest(toJson(TransformValidationErrors.transform(form.errors())));
}
TalkFormat formFormat = form.get();
if (formFormat.getId() == null) {
// Nouveau format
if (TalkFormat.findByLibelle(formFormat.getLibelle(),getEvent()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.format.already.exist"))));
}
formFormat.setEvent(getEvent());
formFormat.save();
} else {
// Mise à jour d'un format
TalkFormat dbFormat = TalkFormat.find.byId(formFormat.getId());
if (!formFormat.getLibelle().equals(dbFormat.getLibelle())
&& TalkFormat.findByLibelle(formFormat.getLibelle(),getEvent()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.format.already.exist"))));
}
dbFormat.setLibelle(formFormat.getLibelle());
dbFormat.setDureeMinutes(formFormat.getDureeMinutes());
dbFormat.setDescription(formFormat.getDescription());
dbFormat.setNbInstance(formFormat.getNbInstance());
dbFormat.update();
}
// HTTP 204 en cas de succès (NO CONTENT)
return noContent();
}