예제 #1
0
        public static String doAddCart(int qty, int medicineId, int userId)
        {
            Cart cp            = CartHandler.getCartMedicine(medicineId, userId);
            int  medicineStock = MedicineHandler.getMedicineById(medicineId).Stock;

            if (qty < 1)
            {
                return("Qty must be more than 0");
            }

            if (cp == null)
            {
                if (qty > medicineStock)
                {
                    return("Qty can't be more than available stock");
                }
                CartHandler.createCartMedicine(userId, medicineId, qty);
                return("");
            }
            else
            {
                int currCartStock = cp.Quantity;
                int requetedStock = currCartStock + qty;


                if (requetedStock > medicineStock)
                {
                    return("Qty must be less than or equals to medicine stocks");
                }
                CartHandler.updateCartMedicineQty(medicineId, userId, requetedStock);
                return("");
            }
        }