Пример #1
0
  /**
   * 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);
  }