/** * Method to delete meal by using meal ID which is unique for each meal. * * @return */ @Security.Authenticated(RestaurantFilter.class) public static Result deleteMeal(int id) { Meal m = Meal.find(id); Restaurant r = m.restaurant; m.restaurant = null; List<Meal> rMeals = r.meals; Iterator<Meal> it = rMeals.iterator(); while (it.hasNext()) { int index = 0; Meal current = it.next(); if (current.id == id) { rMeals.remove(index); break; } index++; } try { Meal.delete(m); Logger.info("Restaurant " + r.name + " just deleted meal."); flash("deletedMeal", "You have successfully deleted your meal"); } catch (Exception e) { Logger.info("Restaurant " + r.name + " just failed to delete meal."); } return redirect("/restaurantOwner/" + Session.getCurrentUser(ctx()).email); }
@Security.Authenticated(RestaurantFilter.class) public static Result editMealURL(int id) { String userEmail = Session.getCurrentUser(ctx()).email; Meal oldMeal = Meal.find(id); User user = Session.getCurrentUser(ctx()); Restaurant restaurant = user.restaurant; return ok(views.html.restaurant.restaurantOwnerEditMeal.render(oldMeal, userEmail, restaurant)); }
public static Result editMeal(int id) { String userEmail = Session.getCurrentUser(ctx()).email; Meal oldMeal = Meal.find(id); String mealName = inputForm.bindFromRequest().field("name").value(); String mealPrice = inputForm.bindFromRequest().field("price").value(); String mealCategory = inputForm.bindFromRequest().field("category").value(); String mealDescription = inputForm.bindFromRequest().field("description").value(); mealPrice = mealPrice.replace(',', '.'); Double price = Double.parseDouble(mealPrice); try { Meal.modifyMeal(oldMeal, mealName, price, mealCategory, mealDescription); flash("successEdited", "You have successfully edited your meal"); Logger.info("User " + userEmail + " just edited meal " + oldMeal.id); } catch (Exception e) { Logger.error("User " + userEmail + " failed to edit meal " + oldMeal.id); } return redirect("/restaurantOwner/" + userEmail); }