Esempio n. 1
0
        /** Aggiorna uno stock
         *
         *  Api Reference: POST /api/stocks/update/<id>/
         *
         *  Requisiti: admin api_key negli header http
         *
         *  JSON Data: {product_id:<id>, price:<pr>, min:<min>, max:<max>, availability:<av>} */

        public JsonResult Update(int id)
        {
            ApiKey k = ApiKey.getApiKey();
            ConvertibleHashtable newData     = ConvertibleHashtable.fromRequest();
            ConvertibleHashtable currentData = Model.getHashtableById <ProductStock>(id);

            currentData.update(newData);
            ProductStock s = currentData.toObject <ProductStock>();

            if (k.isAdmin() || s.checkUserId(k.user_id))
            {
                s.update();
                return(Json(Costants.OK, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet));
            }
        }