Webiant Logo Webiant Logo
  1. No results found.

    Try your search with a different keyword or use * as a wildcard.

CountryStateZipService.cs

using Nop.Core;
using Nop.Core.Caching;
using Nop.Data;
using Nop.Plugin.Tax.FixedOrByCountryStateZip.Domain;
using Nop.Plugin.Tax.FixedOrByCountryStateZip.Infrastructure.Cache;

namespace Nop.Plugin.Tax.FixedOrByCountryStateZip.Services;

/// 
/// Tax rate service
/// 
public class CountryStateZipService : ICountryStateZipService
{
    #region Fields

    protected readonly IRepository _taxRateRepository;
    protected readonly IShortTermCacheManager _shortTermCacheManager;

    #endregion

    #region Ctor

    public CountryStateZipService(IRepository taxRateRepository,
        IShortTermCacheManager shortTermCacheManager)
    {
        _taxRateRepository = taxRateRepository;
        _shortTermCacheManager = shortTermCacheManager;
    }

    #endregion

    #region Methods

    /// 
    /// Deletes a tax rate
    /// 
    /// Tax rate
    /// A task that represents the asynchronous operation
    public virtual async Task DeleteTaxRateAsync(TaxRate taxRate)
    {
        await _taxRateRepository.DeleteAsync(taxRate);
    }

    /// 
    /// Gets all tax rates
    /// 
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the ax rates
    /// 
    public virtual async Task> GetAllTaxRatesAsync(int pageIndex = 0, int pageSize = int.MaxValue)
    {
        var rez = await _shortTermCacheManager.GetAsync(async () => await _taxRateRepository.GetAllAsync(query => from tr in query
            orderby tr.StoreId, tr.CountryId, tr.StateProvinceId, tr.Zip, tr.TaxCategoryId
            select tr), ModelCacheEventConsumer.TAXRATE_ALL_KEY);

        var records = new PagedList(rez, pageIndex, pageSize);

        return records;
    }

    /// 
    /// Gets a tax rate
    /// 
    /// Tax rate identifier
    /// 
    /// A task that represents the asynchronous operation
    /// The task result contains the ax rate
    /// 
    public virtual async Task GetTaxRateByIdAsync(int taxRateId)
    {
        return await _taxRateRepository.GetByIdAsync(taxRateId);
    }

    /// 
    /// Inserts a tax rate
    /// 
    /// Tax rate
    /// A task that represents the asynchronous operation
    public virtual async Task InsertTaxRateAsync(TaxRate taxRate)
    {
        await _taxRateRepository.InsertAsync(taxRate);
    }

    /// 
    /// Updates the tax rate
    /// 
    /// Tax rate
    /// A task that represents the asynchronous operation
    public virtual async Task UpdateTaxRateAsync(TaxRate taxRate)
    {
        await _taxRateRepository.UpdateAsync(taxRate);
    }

    #endregion
}