/// <summary> /// Gets the tax rate information for ZIP centroid and stores it locally. /// </summary> /// <param name="zip">The ZIP code for which you want a ZIP-only tax rate.</param> /// <param name="path">The path where you stored ZIP-only files.</param> /// <returns>The tax rate model object for the requested ZIP, if available</returns> public static TaxRateModel GetLocalTaxRateByZip(string zip, string path) { try { TaxRateModel zipRate = null; //First see if the ZIP rate file is available in the dictionary. if (_ratesByZip.ContainsKey(zip)) { zipRate = _ratesByZip[zip]; } else if (VerifyLocalZipRateAvailable(zip, path)) { _ratesByZip.Add(zip, ReadZipRateFile(zip, path)); zipRate = _ratesByZip[zip]; } return(zipRate); } catch (Exception exc) { throw new AvaTaxOfflineHelperException("An error occurred retrieving local rate content. Please see inner exception for details.", exc); } }
/// <summary>Writes the ZIP rate file to the designated location.</summary> /// <param name="zipRate">The ZIP rate object to store locally.</param> /// <param name="zip">The ZIP code of the rate object.</param> /// <param name="path">The path in which to store the file.</param> private static void WriteZipRateFile(TaxRateModel zipRate, string zip, string path) { var content = JsonConvert.SerializeObject(zipRate); File.WriteAllText(Path.Combine(path, zip + ".json"), content); }