コード例 #1
0
        public async Task <StockItem> GetStockItemAsync(string productSku, Mark mark = null)
        {
            var webRequest = ( WebRequest )WebRequest.Create()
                             .Method(MagentoWebRequestMethod.Get)
                             .Path(MagentoServicePath.Create(
                                       MagentoServicePath.StockItemsPath +
                                       $"/{Uri.EscapeDataString( productSku )}"))
                             .AuthToken(this.Token)
                             .Url(this.Url);

            return(await ActionPolicies.RepeatOnChannelProblemAsync.Get(async() =>
            {
                try
                {
                    using (var v = await webRequest.RunAsync(mark).ConfigureAwait(false))
                    {
                        return JsonConvert.DeserializeObject <StockItem>(new StreamReader(v, Encoding.UTF8).ReadToEnd());
                    }
                }
                catch (MagentoWebException exception)
                {
                    if (exception.IsNotFoundException())
                    {
                        return null;
                    }
                    throw;
                }
            }));
        }
コード例 #2
0
        public async Task <bool> PutStockItemAsync(string productSku, string itemId, RootObject stockItem, Mark mark = null)
        {
            var webRequest = ( WebRequest )WebRequest.Create()
                             .Method(MagentoWebRequestMethod.Put)
                             .Path(MagentoServicePath.Create(
                                       MagentoServicePath.ProductsPath +
                                       $"/{Uri.EscapeDataString( productSku )}/" +
                                       MagentoServicePath.StockItemsPath +
                                       $"/{itemId}"))
                             .Body(JsonConvert.SerializeObject(stockItem, new JsonSerializerSettings()
            {
                NullValueHandling = NullValueHandling.Ignore
            }))
                             .AuthToken(this.Token)
                             .Url(this.Url);

            return(await ActionPolicies.RepeatOnChannelProblemAsync.Get(async() =>
            {
                try
                {
                    using (var v = await webRequest.RunAsync(mark).ConfigureAwait(false))
                    {
                        return JsonConvert.DeserializeObject <int>(new StreamReader(v, Encoding.UTF8).ReadToEnd()) == 1;
                    }
                }
                catch (MagentoWebException exception)
                {
                    if (exception.IsNotFoundException())
                    {
                        return false;
                    }
                    throw;
                }
            }));
        }