Esempio n. 1
0
        GetLenovoMaterials(IEnumerable <string> materialNumbers,
                           string plant)
        {
            var result = new Dictionary <string, (Materiallist material, Materialplantlist plant, Materialdescribelist description)>();
            var client = new HttpClient();

            // client.DefaultRequestHeaders.Add("Content-Type", "application/json");
            var materlNumberSet = new HashSet <string>(materialNumbers);
            var uri             = new Uri(
                "https://api-cn-t.lenovo.com/uat/v1.0/supply_chain/masterdata/plant_material_description/queryByPlant");

            var data = "{\"clientList\": [\"301\"],\"customsMaterialNumberList\": [" + string.Join(",",
                                                                                                   materlNumberSet
                                                                                                   .Select(id => "\"" + id.Replace("-", "") + "\"")) +
                       "],\"languageCodeList\": [\"E\"],\"plantList\": [\"" + plant + "\"]} ";
            var content = new StringContent(data);

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var token = await LenovoTokenClient.GetTokenFromCache("40tI7PHRRHUoToHV0eSG7rulr38a", "iJMoZIjJyd2ZERXFwQw8oRhuNH8a");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
            CatalogResponse obj = null;

            while (obj == null || (obj.code == "-1" && obj.msg.Contains("Null")))
            {
                var res = await(await client.PostAsync(uri, content))
                          .Content.ReadAsStringAsync();
                obj = JsonConvert.DeserializeObject <CatalogResponse>(res);
            }

            foreach (var materialNumber in materlNumberSet)
            {
                var material = obj.result.materialList.FirstOrDefault(m => m.materialNumber == materialNumber);
                if (material == null)
                {
                    continue;
                }
                result.Add(materialNumber, (material,
                                            obj.result.materialPlantList.FirstOrDefault(p => p.materialNumber == materialNumber),
                                            obj.result.materialDescribeList.FirstOrDefault(d => d.materialNumber == materialNumber)));
            }

            return(result);
        }
        public static async Task <InventoryResponse> PostInvetoryData(InventoryData data)
        {
            var client = new HttpClient();

            var uri = new Uri(
                "https://api-cn-t.lenovo.com/uat/v1.0/supply_chain/gl/dc/stock");

            var content = new StringContent(JsonConvert.SerializeObject(data));

            content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
            var token = await LenovoTokenClient.GetTokenFromCache("40tI7PHRRHUoToHV0eSG7rulr38a",
                                                                  "iJMoZIjJyd2ZERXFwQw8oRhuNH8a");

            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);

            var res = await(await client.PostAsync(uri, content))
                      .Content.ReadAsStringAsync();

            return(JsonConvert.DeserializeObject <InventoryResponse>(res));
        }
Esempio n. 3
0
        GetChangedLenovoMaterials()
        {
            var result = new List <Datalist>();
            var client = new HttpClient();

            // client.DefaultRequestHeaders.Add("Content-Type", "application/json");
            int?nextId = 1;
            var uri    = new Uri(
                "https://api-cn-t.lenovo.com/uat/v1.0/supply_chain/masterdata/material_plant/list");
            int pages = 0;

            while (nextId != null)
            {
                var data =
                    "{\"clientList\": [\"301\"],\"plantList\": [\"C400\", \"C402\"],\"searchAfterList\": [{ \"sortField\": \"masterOrderShowId\",\"sortFieldValue\": " +
                    +nextId +

                    "}],\"sortFieldVoList\": [{ \"sortField\": \"masterOrderShowId\",\"isAscOrDesc\": \"asc\" }],\"pageSize\": 1000 }";
                var content = new StringContent(data);
                content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                var token = await LenovoTokenClient.GetTokenFromCache("40tI7PHRRHUoToHV0eSG7rulr38a",
                                                                      "iJMoZIjJyd2ZERXFwQw8oRhuNH8a");

                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
                CatalogChangeResponse obj = null;
                while (obj == null || (obj.code == "-1" && obj.msg.Contains("Null")))
                {
                    var res = await(await client.PostAsync(uri, content))
                              .Content.ReadAsStringAsync();
                    obj = JsonConvert.DeserializeObject <CatalogChangeResponse>(res);
                }

                nextId = obj.result.sortFieldVoList?.Length > 0 ? obj.result.sortFieldVoList[0].sortFieldValue : null;

                result.AddRange(obj.result.dataList);
                pages++;
            }


            return(result);
        }