}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
boolean isOk = true;
YFDishCategory dishCategory = new YFDishCategory();
// Vérification des champs
if (req.getParameter("id") != null && !req.getParameter("id").isEmpty()) {
try {
dishCategory = dishCategoryService.getDishCategoryById(Long.parseLong(req.getParameter("id")));
} catch (Exception e) {
req.setAttribute("idError", "Une erreur est survenue lors de la mise à jour de l'employé");
isOk = false;
}
}
if (req.getParameter("name") == null || req.getParameter("name").isEmpty()) {
req.setAttribute("nameError", "Ne doit pas être vide.");
isOk = false;
} else {
dishCategory.setName(req.getParameter("name"));
}
if (isOk) {
if (dishCategory.getId() == null || dishCategory.getId() == 0) {
dishCategoryService.createDishCategory(dishCategory);
} else {
dishCategoryService.updateDishCategory(dishCategory);
}
resp.sendRedirect(req.getContextPath() + "/administrator/dish/list");