Example #1
0
        public Article Editar(int id)
        {
            Article artistor = new Article();

            string  resp        = GetApi(string.Format(urlId, id.ToString()), "GET");
            JObject json        = JObject.Parse(resp);
            var     articlejson = json["article"];
            Article article     = new Article();

            article = JsonConvert.DeserializeObject <Article>(articlejson.ToString());
            Tienda tien = new Tienda();

            return(article);
        }
Example #2
0
        public bool Guardar(int Id, Article articulo)
        {
            Tienda tienda = new Tienda();
            Store  store  = tienda.Editar(articulo.StoreId);


            ASCIIEncoding encoding      = new ASCIIEncoding();
            string        postDataStore = "Id=" + store.Id;

            postDataStore += "&Name=" + store.Name;
            postDataStore += "&Address=" + store.Address;

            string postData = "Id=" + articulo.Id;

            postData += "&StoreId=" + articulo.StoreId;
            postData += "&Store=" + postDataStore;
            postData += "&Name=" + articulo.Name;
            postData += "&Address=" + articulo.Description;
            postData += "&Price=" + articulo.Price;
            postData += "&Total_In_Shelf=" + articulo.Total_In_Shelf;
            postData += "&Total_In_Shelf=" + articulo.Total_In_Shelf;
            byte[] data = encoding.GetBytes(postData);

            // Prepare web request...
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(string.Format(urlsave, Id.ToString()));

            myRequest.Method        = "PUT";
            myRequest.ContentType   = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();

            // Send the data.
            newStream.Write(data, 0, data.Length);
            newStream.Close();
            WebResponse response = myRequest.GetResponse();

            newStream = response.GetResponseStream();
            StreamReader sr        = new StreamReader(newStream);
            var          respuesta = sr.ReadToEnd();
            JObject      json      = JObject.Parse(respuesta);
            bool         resp      = bool.Parse(json["success"].ToString());
            var          d         = JsonConvert.DeserializeObject(json.ToString());

            return(resp);
        }