Exemplo n.º 1
0
        private async Task <Customer> EnrichCustomer(REPO.Customer cust)
        {
            Customer _final = this.TransformCustomer(cust);

            _final.HomePhone = cust.Phones.Where(p => p.PhoneTypeID == "01").FirstOrDefault() != null?cust.Phones.Where(p => p.PhoneTypeID == "01").FirstOrDefault().PhoneNumber : null;

            _final.MobilePhone = cust.Phones.Where(p => p.PhoneTypeID == "04").FirstOrDefault() != null?cust.Phones.Where(p => p.PhoneTypeID == "04").FirstOrDefault().PhoneNumber : null;

            string _accessToken = (User as ClaimsPrincipal).FindFirst("token").Value;

            ServicePartitionClient <HttpCommunicationClient> partitionClient
                = new ServicePartitionClient <HttpCommunicationClient>(communicationFactory, serviceUri, new ServicePartitionKey());

            await partitionClient.InvokeWithRetryAsync(
                async (client) =>
            {
                IEnumerable <Code> _request = CollectionBuilder.BuildCustomerCodesRequest(_final);

                client.HttpClient.SetBearerToken(_accessToken);

                HttpResponseMessage response = await client.HttpClient.PostAsJsonAsync(new Uri(client.Url, "Services/Codes"), _request);

                IEnumerable <Code> _codes = await response.Content.ReadAsAsync <IEnumerable <Code> >();

                _final = this.AddEnterpriseCodesToCustomer(_final, _codes);
            });

            return(_final);
        }