Пример #1
0
  /** CRUD */
  public static JSONObject createGiftTransaction(JSONObject inputJson) {
    JSONObject returnJson = new JSONObject();
    try {
      GiftInventory giftInventory =
          GiftInventoryDAO.getGiftInventoryById((long) inputJson.get(Key.GIFTINVENTORYID));
      if (giftInventory != null) {
        Student student = StudentDAO.getStudentById((long) inputJson.get(Key.STUDENTID));
        if (student != null) {
          long giftQuantity = (long) inputJson.get(Key.GIFTQUANTITY);
          double studentPoints = Double.valueOf((String) inputJson.get(Key.STUDENTPOINTS));

          GiftTransaction giftTransaction =
              new GiftTransaction(giftQuantity, studentPoints, giftInventory, student);
          GiftTransactionDAO.addGiftTransaction(giftTransaction);
          returnJson.put(Key.STATUS, Value.SUCCESS);
          returnJson.put(Key.MESSAGE, giftTransaction.toJsonSimple());
        } else {
          returnJson.put(Key.STATUS, Value.FAIL);
          returnJson.put(Key.MESSAGE, Message.STUDENTNOTEXIST);
        }
      } else {
        returnJson.put(Key.STATUS, Value.FAIL);
        returnJson.put(Key.MESSAGE, Message.GIFTINVENTORYNOTEXIST);
      }
    } catch (Exception e) {
      e.printStackTrace();
      returnJson.put(Key.STATUS, Value.FAIL);
      returnJson.put(Key.MESSAGE, e);
    }
    return returnJson;
  }
Пример #2
0
 // Get giftTransactions by student
 public static JSONObject getGiftTransactionsByStudent(JSONObject inputJson) {
   JSONObject returnJson = new JSONObject();
   try {
     Student student = StudentDAO.getStudentById((long) inputJson.get(Key.STUDENTID));
     if (student != null) {
       JSONArray giftTransactionArr = new JSONArray();
       for (GiftTransaction giftTransaction :
           GiftTransactionDAO.getGiftTransactionsByStudent(student)) {
         giftTransactionArr.add(giftTransaction.toJsonSimple());
       }
       returnJson.put(Key.STATUS, Value.SUCCESS);
       returnJson.put(Key.MESSAGE, giftTransactionArr);
     } else {
       returnJson.put(Key.STATUS, Value.FAIL);
       returnJson.put(Key.MESSAGE, Message.STUDENTNOTEXIST);
     }
   } catch (Exception e) {
     e.printStackTrace();
     returnJson.put(Key.STATUS, Value.FAIL);
     returnJson.put(Key.MESSAGE, e);
   }
   return returnJson;
 }