}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
YFRestaurant restaurant = new YFRestaurant();
boolean isOk = true;
if (req.getParameter("id") != null && !req.getParameter("id").isEmpty()) {
try {
restaurant = restaurantService.getRestaurant(Long.parseLong(req.getParameter("id")));
req.setAttribute("isRestaurantEdition", true);
} catch (Exception e) {
System.out.println("ID en chaine de caractères.");
req.setAttribute("idError", "Une erreur est survenue lors de la mise à jour du restaurant");
isOk = false;
}
}
if (req.getParameter("name") == null || req.getParameter("name").isEmpty()) {
req.setAttribute("nameError", "Ne doit pas être vide.");
isOk = false;
} else if ((restaurant.getId() == null || restaurant.getId() <= 0) && restaurantService.getRestaurant(req.getParameter("name")) != null) {
req.setAttribute("nameError", "Le nom du restaurant est déjà pris.");
isOk = false;
}
// Si le restaurant existe et que nous voulons changer le mdp
/* if (restaurant.getId() != null && restaurant.getId() > 0) {
if (req.getParameter("changePassword") != null && req.getParameter("changePassword").equals("on")) {
req.setAttribute("changePasswordIsSelected", "checked");
if (req.getParameter("password") == null || req.getParameter("password").isEmpty()) {
req.setAttribute("passwordError", "Ne doit pas être vide.");
isOk = false;
}
}
} else {
// Si le restaurant est nouveau, nous devons obligatoirement mettre un mdp
if (req.getParameter("password") == null || req.getParameter("password").isEmpty()) {
req.setAttribute("passwordError", "Ne doit pas être vide.");
isOk = false;
}
}*/
restaurant.setAddress(req.getParameter("address").toString());
restaurant.setName(req.getParameter("name").toString());
//restaurant.setPassword(req.getParameter("password").toString());
if (isOk) {
if (restaurant.getId() == null || restaurant.getId() == 0) {
restaurantService.createRestaurant(restaurant);
} else {
restaurantService.updateRestaurant(restaurant);
}