/** Aggiorna una categoria
         *
         *  API Reference: POST /api/categories/update/<id>/
         *
         *  Requisiti: admin api_key negli header http
         *
         *  JSON Data: {name: "name"} */

        public JsonResult Update(int id)
        {
            if (!ApiKey.getApiKey().isAdmin())
            {
                return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet));
            }
            else
            {
                ConvertibleHashtable newData     = ConvertibleHashtable.fromRequest();
                ConvertibleHashtable currentData = Model.getHashtableById <ProductCategory>(id);
                currentData.update(newData);
                currentData.toObject <ProductCategory>().update();
                return(Json(Costants.OK, JsonRequestBehavior.AllowGet));
            }
        }
예제 #2
0
        public JsonResult Update(int id)
        {
            ApiKey k = ApiKey.getApiKey();
            ConvertibleHashtable newData     = ConvertibleHashtable.fromRequest();
            ConvertibleHashtable currentData = Model.getHashtableById <Product>(id);

            if (k.isAdmin() || Supplier.checkUserId(k.user_id, int.Parse(currentData["supplier_id"].ToString())))
            {
                currentData.update(newData);
                currentData.toObject <Product>().update();
                return(Json(Costants.OK, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet));
            }
        }
예제 #3
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));
            }
        }
예제 #4
0
        public JsonResult Update(int id)
        {
            ConvertibleHashtable h = ConvertibleHashtable.fromRequest();
            ApiKey k = ApiKey.getApiKey();

            if (k.isAdmin() || k.checkUser(id))
            {
                // controlla se si deve modificare le informazioni specifiche di un supplier
                ConvertibleHashtable supplierCurrentData = Supplier.getHashtableByUserId(id);
                if (h.ContainsKey("supplier_data") && supplierCurrentData["user_id"].ToString() == id.ToString())
                {
                    ConvertibleHashtable newData = ConvertibleHashtable.fromJObject((JObject)h["supplier_data"]);
                    if (h.ContainsKey("user_data"))
                    {
                        newData.merge(ConvertibleHashtable.fromJObject((JObject)h["user_data"]));
                    }
                    supplierCurrentData.update(newData);
                    if (!supplierCurrentData.ContainsKey("user_id"))
                    {
                        supplierCurrentData.Add("user_id", id);
                    }
                    supplierCurrentData.toObject <Supplier>().update();
                }
                // modifica le info di base dell'utente, che sia admin o supplier
                else
                {
                    ConvertibleHashtable currentData = Model.getHashtableById <User>(id);
                    ConvertibleHashtable newData     = ConvertibleHashtable.fromJObject((JObject)h["user_data"]);
                    currentData.update(newData);
                    currentData.toObject <User>().update();
                }
                // aggiorna le api key per riflettere evenutali modifiche alla password o alla mail
                ApiKey.fromUserId(id).update();
                return(Json(Costants.OK, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet));
            }
        }