if (evenForm.hasErrors()) {
return badRequest(toJson(TransformValidationErrors.transform(evenForm.errors())));
}
Event formEvent = evenForm.get();
if (formEvent.getId() == null) {
// Nouvel Evénement
if (Event.findByName(formEvent.getName()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.event.already.exist"))));
}
formEvent.save();
List<User> organizersInDb = new ArrayList<User>();
for (User organizer : formEvent.getOrganizers()) {
organizersInDb.add(User.findById(organizer.id));
}
formEvent.getOrganizers().clear();
formEvent.getOrganizers().addAll(organizersInDb);
formEvent.saveManyToManyAssociations("organizers");
formEvent.update();
} else {
// Mise à jour d'un événement
Event dbEvent = Event.find.byId(formEvent.getId());
if (!formEvent.getName().equals(dbEvent.getName())
&& Event.findByName(formEvent.getName()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.event.already.exist"))));
}
dbEvent.setUrl(formEvent.getUrl());
dbEvent.setShortName(formEvent.getShortName());
dbEvent.setCgu(formEvent.getCgu());
dbEvent.logo = formEvent.logo;
dbEvent.setDescription(formEvent.getDescription());
dbEvent.update();
updateOrganizers(formEvent, dbEvent);
}
// HTTP 204 en cas de succès (NO CONTENT)