Example #1
0
        static public string CreateProduct(EvotorProductV2 product)
        {
            var path    = ADDRESS + "stores/" + STORE_ID + "/products";
            var request = WebRequest.Create(path);

            request.Headers["Authorization"] = TOKEN;
            request.Method      = "POST";
            request.ContentType = "application/vnd.evotor.v2+json";

            string barcodes = JsonConvert.SerializeObject(product.barcodes);
            string js       = "{\"code\":\"" + product.code + "\",\"name\":\"" + product.name + "\",\"allow_to_sell\":true," + "\"type\":\"NORMAL\",\"quantity\":" + product.quantity + ",\"measure_name\":\"шт\",\"tax\":\"NO_VAT\",\"price\":" + product.price +
                              ",\"cost_price\":" + product.cost_price + ",\"description\":\"" + product.description + "\"" + ",\"article_number\":\"" + product.article_number + "\",\"barcodes\":" + barcodes + ((product.parent_id == String.Empty) ? "" : (",\"parent_id\":\"" + product.parent_id + "\""));

            js += "}";

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                streamWriter.Write(js);
            }

            string          json     = String.Empty;
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                json += reader.ReadToEnd();
            }

            StatusTask status = JsonConvert.DeserializeObject <StatusTask>(json);

            return(status.id);
        }
Example #2
0
        static public string CreateGroup(string groupName)
        {
            var path    = ADDRESS + "stores/" + STORE_ID + "/product-groups";
            var request = WebRequest.Create(path);

            request.Headers["Authorization"] = TOKEN;
            request.Method      = "POST";
            request.ContentType = "application/vnd.evotor.v2+json";

            using (var streamWriter = new StreamWriter(request.GetRequestStream()))
            {
                string js = "{\"name\":\"" + groupName + "\"" + "}";
                streamWriter.Write(js);
            }

            string          json     = String.Empty;
            HttpWebResponse response = request.GetResponse() as HttpWebResponse;

            using (Stream responseStream = response.GetResponseStream())
            {
                StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
                json += reader.ReadToEnd();
            }

            StatusTask status = JsonConvert.DeserializeObject <StatusTask>(json);

            return(status.id);
        }