Exemplo n.º 1
0
        public IEnumerable <SalesRegionResource> GetSalesRegions()
        {
            var uri      = new Uri($"{this.rootUri}/sales-regions", UriKind.RelativeOrAbsolute);
            var response = this.restClient.Get(
                CancellationToken.None,
                uri,
                new Dictionary <string, string>(),
                DefaultHeaders.JsonGetHeaders()).Result;

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ProxyException($"Error trying to get sales regions");
            }

            var json = new JsonSerializer();

            return(json.Deserialize <IEnumerable <SalesRegionResource> >(response.Value));
        }
Exemplo n.º 2
0
        public string GetRootProductUri(string salesPartUri)
        {
            if (!salesPartUri.Contains("sales-parts"))
            {
                return(null);
            }

            var uri      = new Uri($"{this.rootUri}{salesPartUri}", UriKind.RelativeOrAbsolute);
            var response = this.restClient.Get(
                CancellationToken.None,
                uri,
                new Dictionary <string, string>(),
                DefaultHeaders.JsonGetHeaders()).Result;

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ProxyException($"Error sales part details for {salesPartUri}.");
            }

            var json      = new JsonSerializer();
            var salesPart = json.Deserialize <RetailerResource>(response.Value);

            return(salesPart.Links.FirstOrDefault(l => l.Rel == "root-product")?.Href);
        }
Exemplo n.º 3
0
        public int?GetRetailerId(string salesCustomerUri)
        {
            var uri      = new Uri($"{this.rootUri}/retailers?salesCustomer={salesCustomerUri}", UriKind.RelativeOrAbsolute);
            var response = this.restClient.Get(
                CancellationToken.None,
                uri,
                new Dictionary <string, string>(),
                DefaultHeaders.JsonGetHeaders()).Result;

            if (response.StatusCode != HttpStatusCode.OK)
            {
                throw new ProxyException($"Error trying to find retailer for sales customer {salesCustomerUri}.");
            }

            var json      = new JsonSerializer();
            var retailers = json.Deserialize <RetailerResources>(response.Value);

            if (retailers.Retailers.Length > 0)
            {
                return(retailers.Retailers[0].Id);
            }

            return(null);
        }