if (dynamicFieldForm.hasErrors()) {
return badRequest(toJson(TransformValidationErrors.transform(dynamicFieldForm.errors())));
}
DynamicField formDynamicField = dynamicFieldForm.get();
if (formDynamicField.getId() == null) {
// Nouveau dynamicField
if (DynamicField.findByName(formDynamicField.getName()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.dynamicField.already.exist"))));
}
formDynamicField.save();
} else {
// Mise à jour d'un dynamicField
DynamicField dbDynamicField = DynamicField.find.byId(formDynamicField.getId());
if (!formDynamicField.getName().equals(dbDynamicField.getName())
&& DynamicField.findByName(formDynamicField.getName()) != null) {
return badRequest(toJson(TransformValidationErrors.transform(Messages.get("error.dynamicField.already.exist"))));
}
dbDynamicField.setName(formDynamicField.getName());
dbDynamicField.update();
}
// HTTP 204 en cas de succès (NO CONTENT)
return noContent();
}