/** Elimina uno stock * * Api Reference: GET /api/stocks/delete/<id>/ * * Requisiti: admin api_key negli header http */ public JsonResult Delete(int id) { ApiKey k = ApiKey.getApiKey(); ProductStock ps = Model.getById <ProductStock>(id); if (k.isAdmin() || ps.checkUserId(k.user_id)) { ps.delete(); return(Json(Costants.OK, JsonRequestBehavior.AllowGet)); } else { return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet)); } }
/** Aggiunge uno stock * * Api Reference: POST /api/stocks/ * * Requisiti: admin api_key negli header http * * JSON Data: {product_id:<id>, price:<pr>, min:<min>, max:<max>, availability:<av>} */ public JsonResult Index() { ApiKey k = ApiKey.getApiKey(); ProductStock s = ConvertibleHashtable.fromRequest().toObject <ProductStock>(); if (k.isAdmin() || s.checkUserId(k.user_id)) { s.insert(); return(Json(Costants.OK, JsonRequestBehavior.AllowGet)); } else { return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet)); } }
/** 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)); } }