@RequestMapping(value = "/pizzeria/pizzasList", method = RequestMethod.GET)
  public @ResponseBody List<RelationPizzeriaPizza> getPizzas(HttpSession session) {
    /*
     * If the author of the request is not logged in as a pizzeria, negate
     * the information.
     */
    if (!SessionUtils.isPizzeria(session)) {
      return null;
    }

    PizzeriaDAO pizzeriaDAO = (PizzeriaDAO) context.getBean("pizzeriaDAO");
    Pizzeria pizzeria = pizzeriaDAO.get(SessionUtils.getPizzeriaIdFromSessionOrNull(session));

    return pizzeria.getAvailablePizzasPriceList();
  }
  @RequestMapping(value = "/userBooking", method = RequestMethod.GET)
  public String bookingCart(Model model, HttpSession session) {
    if (!SessionUtils.isUser(session)) {
      return "index";
    }
    UserDAO userDAO = (UserDAO) context.getBean("userDAO");
    User user = userDAO.get(SessionUtils.getUserIdFromSessionOrNull(session));
    CartDAO cartDAO = (CartDAO) context.getBean("cartDAO");
    Cart cart = cartDAO.getUserCart(user);

    ArrayList<CartBooking> bookings = createBookingsToDisplay(cart);
    model.addAttribute("bookings", bookings);
    model.addAttribute("user", user);

    return "userBooking";
  }
  @RequestMapping(value = "/pizzeriaPizzaManager", method = RequestMethod.GET)
  public String pizzeriaPizzaManager(Model model, HttpSession session) {
    if (!SessionUtils.isPizzeria(session)) {
      return "homeLogInError";
    } else {
      PizzaDAO pizzaDAO = (PizzaDAO) context.getBean("pizzaDAO");
      List<Pizza> pizzas = pizzaDAO.getAll();

      model.addAttribute("pizzas", pizzas);
      model.addAttribute("sizes", PizzaSize.values());

      return "pizzeriaPizzaManager";
    }
  }
  @ResponseBody
  @RequestMapping(value = "/pizzeria/pizza", method = RequestMethod.POST)
  public String handleRequest(HttpSession session, @ModelAttribute PizzeriaPizzaForm form) {
    if (!SessionUtils.isPizzeria(session)) {
      return null;
    }

    PizzeriaDAO pizzeriaDAO = (PizzeriaDAO) context.getBean("pizzeriaDAO");
    Pizzeria pizzeria = pizzeriaDAO.get(SessionUtils.getPizzeriaIdFromSessionOrNull(session));

    PizzaDAO pizzaDAO = (PizzaDAO) context.getBean("pizzaDAO");
    Pizza pizza = pizzaDAO.get(form.getPizzaId());

    switch (form.getAction()) {
      case "add":
        return addPizza(pizzeria, pizza, form);
      case "update":
        return updatePizza(pizzeria, pizza, form);
      case "delete":
        return deletePizza(pizzeria, pizza, form);
    }

    return buildErrorResponse();
  }
  @ResponseBody
  @RequestMapping(value = "/userBooking/book", method = RequestMethod.POST)
  public String book(
      @RequestParam String type,
      @RequestParam String pizzeria,
      @RequestParam String date,
      @RequestParam String time,
      Model model,
      HttpSession session) {

    SimpleDateFormat sdfDate = new SimpleDateFormat("dd/M/yyyy");
    SimpleDateFormat sdfTime = new SimpleDateFormat("hh:mm");
    Date d = null;
    Date t = null;
    try {
      d = sdfDate.parse(date);
      t = sdfTime.parse(time);

    } catch (ParseException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    DateFormat dateFormat = new SimpleDateFormat("dd/M/yyyy hh:mm");
    Date today = new Date();
    if (today.getTime() > d.getTime() + t.getTime()) return "dateError";
    // set correctly date
    UserDAO userDAO = (UserDAO) context.getBean("userDAO");
    BookingDAO bookingDAO = (BookingDAO) context.getBean("bookingDAO");
    CartDAO cartDAO = (CartDAO) context.getBean("cartDAO");
    PizzeriaDAO pizzeriaDAO = (PizzeriaDAO) context.getBean("pizzeriaDAO");
    OrderItemDAO orderItemDAO = (OrderItemDAO) context.getBean("orderItemDAO");

    User user = userDAO.get(SessionUtils.getUserIdFromSessionOrNull(session));
    Cart cart = cartDAO.getUserCart(user);
    ArrayList<OrderItem> toBook = itemToBook(pizzeria, cart);
    Pizzeria pizzerias = pizzeriaDAO.getByName(pizzeria);
    Booking booking = createBooking(type);
    booking.setConfirmed(false);
    booking.setDate(d);
    booking.setTime(t);
    booking.setPizzeria(pizzerias);
    booking.setUser(user);

    if (booking instanceof BookingDelivery)
      ((BookingDelivery) booking).setDeliveryAddress(user.getAddress());
    booking.setBill(BookingUserDisplayUtils.calculateBill(toBook));

    bookingDAO.create(booking);

    for (OrderItem orderItem : toBook) {
      orderItem.setBooking(booking);
      orderItem.setCart(null);
      if (orderItem instanceof PizzaOrderItem)
        OrderItemUtils.setPizzaOrderCost((PizzaOrderItem) orderItem, pizzerias);
      else if (orderItem instanceof BeverageOrderItem)
        OrderItemUtils.setBeverageOrderCost((BeverageOrderItem) orderItem, pizzerias);
      orderItemDAO.update(orderItem);
    }
    booking.setOrderItems(toBook);
    bookingDAO.update(BookingUtils.calculateBill(booking, pizzerias));
    // ArrayList<CartBooking> bookings = createBookingsToDisplay(cart);
    // model.addAttribute("bookings", bookings);
    model.addAttribute("user", user);
    return "{\"success\" : true}";
  }