if (audienceForm.hasErrors()) {
return badRequest(toJson(TransformValidationErrors.transform(audienceForm.errors())));
}
Audience formAudience = audienceForm.get();
if (formAudience.getId() == null) {
// Nouveau Track
if (Audience.findByTitleAndEvent(formAudience.getTitle(),getEvent()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.audience.already.exist"))));
}
formAudience.setEvent(getEvent());
formAudience.save();
} else {
// Mise à jour d'un track
Audience dbAudience = Audience.find.byId(formAudience.getId());
if (!formAudience.getTitle().equals(dbAudience.getTitle())
&& Audience.findByTitleAndEvent(formAudience.getTitle(),getEvent()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.audience.already.exist"))));
}
dbAudience.setTitle(formAudience.getTitle());
dbAudience.setDescription(formAudience.getDescription());
dbAudience.update();
}
// HTTP 204 en cas de succès (NO CONTENT)
return noContent();
}