示例#1
0
 /// <summary>
 /// Gets tax rate
 /// </summary>
 /// <param name="calculateTaxRequest">Tax calculation request</param>
 /// <returns>Tax</returns>
 public CalculateTaxResult GetTaxRate(CalculateTaxRequest calculateTaxRequest)
 {
     var result = new CalculateTaxResult()
     {
         TaxRate = GetTaxRate(calculateTaxRequest.TaxCategoryId)
     };
     return result;
 }
        /// <summary>
        /// Gets tax rate
        /// </summary>
        /// <param name="calculateTaxRequest">Tax calculation request</param>
        /// <returns>Tax</returns>
        public CalculateTaxResult GetTaxRate(CalculateTaxRequest calculateTaxRequest)
        {
            var result = new CalculateTaxResult();

            if (calculateTaxRequest.Address == null)
            {
                result.Errors.Add("Address is not set");
                return result;
            }

            var taxRates = _taxRateService.GetAllTaxRates(calculateTaxRequest.TaxCategoryId,
                calculateTaxRequest.Address.Country != null ? calculateTaxRequest.Address.Country.Id: 0,
                calculateTaxRequest.Address.StateProvince != null ? calculateTaxRequest.Address.StateProvince.Id : 0,
                calculateTaxRequest.Address.ZipPostalCode);
            if (taxRates.Count > 0)
                result.TaxRate = taxRates[0].Percentage;

            return result;
        }