public static String DoAddCart(int qty, int productId, int userId) { Cart cp = CartHandler.getCartProduct(productId, userId); int productStock = ProductHandler.getProductByID(productId).Stock; if (qty < 1) { return("Quantity must be more than 0"); } if (cp == null) { if (qty > productStock) { return("Quantity can't be more than available stock"); } CartHandler.createCartProduct(userId, productId, qty); return(""); } else { int currCartStock = cp.Quantity; int totalRequestStock = currCartStock + qty; if (totalRequestStock > productStock) { return("Quantity must be less than or equals to product stocks"); } CartHandler.updateCartProductQty(productId, userId, totalRequestStock); return(""); } }