using Nop.Core; using Nop.Data; using Nop.Plugin.Tax.Avalara.Domain; namespace Nop.Plugin.Tax.Avalara.Services; /// /// Represents the tax transaction log service implementation /// public class TaxTransactionLogService { #region Fields protected readonly IRepository _taxTransactionLogRepository; #endregion #region Ctor public TaxTransactionLogService(IRepository taxTransactionLogRepository) { _taxTransactionLogRepository = taxTransactionLogRepository; } #endregion #region Methods /// /// Get tax transaction log /// /// Customer identifier; pass null to load all records /// Log item creation from; pass null to load all records /// Log item creation to; pass null to load all records /// Page index /// Page size /// /// A task that represents the asynchronous operation /// The task result contains the paged list of tax transaction log items /// public async Task> GetTaxTransactionLogAsync(int? customerId = null, DateTime? createdFromUtc = null, DateTime? createdToUtc = null, int pageIndex = 0, int pageSize = int.MaxValue) { //get all logs var query = _taxTransactionLogRepository.Table; //filter by customer if (customerId.HasValue) query = query.Where(logItem => logItem.CustomerId == customerId); //filter by dates if (createdFromUtc.HasValue) query = query.Where(logItem => logItem.CreatedDateUtc >= createdFromUtc.Value); if (createdToUtc.HasValue) query = query.Where(logItem => logItem.CreatedDateUtc <= createdToUtc.Value); //order log records query = query.OrderByDescending(logItem => logItem.CreatedDateUtc).ThenByDescending(logItem => logItem.Id); //return paged log return await query.ToPagedListAsync(pageIndex, pageSize); } /// /// Get a log item by the identifier /// /// Log item identifier /// /// A task that represents the asynchronous operation /// The task result contains the log item /// public async Task GetTaxTransactionLogByIdAsync(int logItemId) { return await _taxTransactionLogRepository.GetByIdAsync(logItemId); } /// /// Insert the log item /// /// Log item /// A task that represents the asynchronous operation public async Task InsertTaxTransactionLogAsync(TaxTransactionLog logItem) { ArgumentNullException.ThrowIfNull(logItem); await _taxTransactionLogRepository.InsertAsync(logItem, false); } /// /// Update the log item /// /// Log item /// A task that represents the asynchronous operation public async Task UpdateTaxTransactionLogAsync(TaxTransactionLog logItem) { ArgumentNullException.ThrowIfNull(logItem); await _taxTransactionLogRepository.UpdateAsync(logItem, false); } /// /// Delete the log item /// /// Log item /// A task that represents the asynchronous operation public async Task DeleteTaxTransactionLogAsync(TaxTransactionLog logItem) { await _taxTransactionLogRepository.DeleteAsync(logItem, false); } /// /// Delete log items /// /// Log items identifiers /// A task that represents the asynchronous operation public async Task DeleteTaxTransactionLogAsync(int[] ids) { await _taxTransactionLogRepository.DeleteAsync(logItem => ids.Contains(logItem.Id)); } /// /// Clear the log /// /// A task that represents the asynchronous operation public async Task ClearLogAsync() { await _taxTransactionLogRepository.TruncateAsync(); } #endregion }