Пример #1
0
  @RequestMapping(value = "/placeorder")
  public ModelAndView billingAndUpdateInventory(
      @RequestParam("username") String username,
      @RequestParam("prodId") int prodId,
      @RequestParam("prodType") String prodType,
      @RequestParam("prodRate") double rate,
      @RequestParam("quantity") int quantityByUser,
      @RequestParam("cardNo") String cardNo) {

    System.out.println("in billing");
    System.out.println("username inside billing controller:" + username);
    // TODO :
    // 1) Check if card number is valid
    double totalRate = quantityByUser * rate;
    ModelAndView mv = new ModelAndView();

    DBConnection connection = new DBConnection();
    boolean result = connection.validateCard(cardNo, username);
    int orderid = -1;
    if (result) {
      orderid = connection.pay(username, prodType, quantityByUser, totalRate, cardNo, prodId);
      if (orderid != -1) {
        int temp = quantityByUser;
        while (temp != 0) {
          result = connection.decrementcount(prodType, prodId);
          temp--;
        }
        System.out.println(
            "username and orderid in billing cntrl just before "
                + "setting in confirm = "
                + username
                + ", "
                + orderid);

        mv.addObject("success", "Done! Successully placed the order");
        mv.addObject("orderid", orderid);
        mv.addObject("username", username);
        mv.setViewName("done");
      } else {
        mv.addObject("error", "Database down! Please come back later.");
        mv.setViewName("error");
      }
    } else {
      mv.addObject("error", "Invalid input! Please enter a valid Card.");
      mv.setViewName("error");
    }

    return mv;
  }