Exemplo n.º 1
0
        /// <summary>
        /// Gets all tax rates by params
        /// </summary>
        /// <param name="TaxCategoryID">The tax category identifier</param>
        /// <param name="CountryID">The country identifier</param>
        /// <param name="StateProvinceID">The state/province identifier</param>
        /// <param name="Zip">The zip</param>
        /// <returns>Tax rate collection</returns>
        public static TaxRateCollection GetAllTaxRates(int TaxCategoryID, int CountryID,
                                                       int StateProvinceID, string Zip)
        {
            if (Zip == null)
            {
                Zip = string.Empty;
            }
            if (!String.IsNullOrEmpty(Zip))
            {
                Zip = Zip.Trim();
            }

            TaxRateCollection existingRates = GetAllTaxRates().FindTaxRates(CountryID, TaxCategoryID);

            //filter by state/province
            TaxRateCollection matchedByStateProvince = new TaxRateCollection();

            foreach (TaxRate taxRate in existingRates)
            {
                if (StateProvinceID == taxRate.StateProvinceID)
                {
                    matchedByStateProvince.Add(taxRate);
                }
            }
            if (matchedByStateProvince.Count == 0)
            {
                foreach (TaxRate taxRate in existingRates)
                {
                    if (taxRate.StateProvinceID == 0)
                    {
                        matchedByStateProvince.Add(taxRate);
                    }
                }
            }

            //filter by zip
            TaxRateCollection matchedByZip = new TaxRateCollection();

            foreach (TaxRate taxRate in matchedByStateProvince)
            {
                if (Zip.ToLower() == taxRate.Zip.ToLower())
                {
                    matchedByZip.Add(taxRate);
                }
            }
            if (matchedByZip.Count == 0)
            {
                foreach (TaxRate taxRate in matchedByStateProvince)
                {
                    if (taxRate.Zip.Trim() == string.Empty)
                    {
                        matchedByZip.Add(taxRate);
                    }
                }
            }

            return(matchedByZip);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets all tax rates by params
        /// </summary>
        /// <param name="taxCategoryId">The tax category identifier</param>
        /// <param name="countryId">The country identifier</param>
        /// <param name="stateProvinceId">The state/province identifier</param>
        /// <param name="zip">The zip</param>
        /// <returns>Tax rate collection</returns>
        public static TaxRateCollection GetAllTaxRates(int taxCategoryId, int countryId,
                                                       int stateProvinceId, string zip)
        {
            if (zip == null)
            {
                zip = string.Empty;
            }
            if (!String.IsNullOrEmpty(zip))
            {
                zip = zip.Trim();
            }

            var existingRates = GetAllTaxRates().FindTaxRates(countryId, taxCategoryId);

            //filter by state/province
            var matchedByStateProvince = new TaxRateCollection();

            foreach (var taxRate in existingRates)
            {
                if (stateProvinceId == taxRate.StateProvinceId)
                {
                    matchedByStateProvince.Add(taxRate);
                }
            }
            if (matchedByStateProvince.Count == 0)
            {
                foreach (var taxRate in existingRates)
                {
                    if (taxRate.StateProvinceId == 0)
                    {
                        matchedByStateProvince.Add(taxRate);
                    }
                }
            }

            //filter by zip
            var matchedByZip = new TaxRateCollection();

            foreach (var taxRate in matchedByStateProvince)
            {
                if (zip.ToLower() == taxRate.Zip.ToLower())
                {
                    matchedByZip.Add(taxRate);
                }
            }
            if (matchedByZip.Count == 0)
            {
                foreach (var taxRate in matchedByStateProvince)
                {
                    if (taxRate.Zip.Trim() == string.Empty)
                    {
                        matchedByZip.Add(taxRate);
                    }
                }
            }

            return(matchedByZip);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Find records
        /// </summary>
        /// <param name="countryId">Country identifier</param>
        /// <param name="taxCategoryId">Tax category identifier</param>
        /// <returns>Tax rates</returns>
        public TaxRateCollection FindTaxRates(int countryId, int taxCategoryId)
        {
            TaxRateCollection result = new TaxRateCollection();

            foreach (TaxRate taxRate in this)
            {
                if (taxRate.CountryId == countryId && taxRate.TaxCategoryId == taxCategoryId)
                {
                    result.Add(taxRate);
                }
            }
            return(result);
        }
Exemplo n.º 4
0
        private static TaxRateCollection DBMapping(DBTaxRateCollection dbCollection)
        {
            if (dbCollection == null)
            {
                return(null);
            }

            var collection = new TaxRateCollection();

            foreach (var dbItem in dbCollection)
            {
                var item = DBMapping(dbItem);
                collection.Add(item);
            }

            return(collection);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Gets all tax rates
        /// </summary>
        /// <returns>Tax rate collection</returns>
        public static TaxRateCollection GetAllTaxRates()
        {
            string key  = TAXRATE_ALL_KEY;
            object obj2 = NopCache.Get(key);

            if (TaxRateManager.CacheEnabled && (obj2 != null))
            {
                return((TaxRateCollection)obj2);
            }

            DBTaxRateCollection dbCollection = DBProviderManager <DBTaxRateProvider> .Provider.GetAllTaxRates();

            TaxRateCollection collection = DBMapping(dbCollection);

            if (TaxRateManager.CacheEnabled)
            {
                NopCache.Max(key, collection);
            }

            return(collection);
        }