/// <summary>
        /// Adds all LandedCost nexus to a company.
        /// </summary>
        /// <param name="URI">The URI.</param>
        /// <param name="USER">The user.</param>
        /// <param name="COMPANY_ID">The company identifier.</param>
        /// <param name="PASS">The pass.</param>
        private static void AddLcNexusToCompany(string URI, string USER, int COMPANY_ID, string PASS)
        {
            var client = new AvaTaxClient("lcNexusApp",
                                          ".1",
                                          "AvalaraAddLcNexusApp",
                                          new Uri(URI))
                         .WithSecurity(USER, PASS);
            var countriesAlreadyAssigned = client.ListNexusByCompany(COMPANY_ID, "nexusTaxTypeGroup EQ 'LandedCost'", "", null, null, "").value;
            var countries = client.ListNexusByCountry("", "nexusTaxTypeGroup EQ 'LandedCost'", null, null, "").value;
            List <NexusModel> countriesToAdd = new List <NexusModel>();

            foreach (var country in countries)
            {
                if (countriesAlreadyAssigned.Any(cas => cas.country == country.country))
                {
                    continue;
                }

                countriesToAdd.Add(country);
            }

            client.CreateNexus(COMPANY_ID, countriesToAdd);
            Console.WriteLine(string.Format("Added {0} LandedCostNexus to company {1}.",
                                            countriesToAdd.Count,
                                            COMPANY_ID));
        }
Example #2
0
        private static void UpsertPrdNexus(AvaTaxClient prdClient, List <NexusModel> nexus)
        {
            //Get existing PRD nexus.
            var prdNexus = prdClient.ListNexusByCompany(PRD_COMPANY_ID, "nexusTaxTypeGroup EQ LandedCost", string.Empty, null, null, string.Empty).value;

            //Change the company ID to PRD.
            foreach (NexusModel indNexus in nexus)
            {
                //Check if the nexus already exists in the company.
                if (prdNexus.Select(pn => pn.country == indNexus.country).Any())
                {
                    continue;
                }

                try
                {
                    indNexus.companyId = PRD_COMPANY_ID;
                    var nexusToAdd = new List <NexusModel> {
                        indNexus
                    };
                    prdClient.CreateNexus(PRD_COMPANY_ID, nexusToAdd);
                }
                catch (AvaTaxError exc)
                {
                    Console.WriteLine(string.Format("Error in adding nexus", exc.Message, exc.InnerException));
                    Console.WriteLine(string.Format("More information: {0}", exc.error));
                    continue;
                }
                catch (Exception exc)
                {
                    Console.WriteLine(string.Format("Other error occurred in loading nexus: {0}", exc.Message));
                }
            }
        }