public virtual IList <T> Calculate(IList <T> list = null) { var entityId = ""; try { _taxRateDictionary = GetCustomersTaxRate(); var dataService = _oAuthService.GetDataService(); var queryService = _oAuthService.GetQueryService <T>(); var entities = list ?? queryService.Select(x => x).ToList(); // var entities = queryService.Select(x => x).Take(1).ToList(); if (entities.Count == 0) { return(new List <T>()); } foreach (var entity in entities) { entityId = entity.Id; SetTaxCode(entity); var countrySubDivisionCode = entity.ShipAddr?.CountrySubDivisionCode; if (countrySubDivisionCode == null) { continue; } var percent = GetPercent(countrySubDivisionCode); SetTaxCodeRef(percent, entity); if (entity.TxnTaxDetail.TotalTax == 0) { RecalculateTaxManually(entity, percent); } dataService.Update(entity); } return(entities); } catch (ValidationException e) { _log.Error($"Exception occured when application tried to recalculate sales tax in {EntityName} with id = {entityId}", e); throw; } catch (Exception e) { if (e.Message.Contains("An error occured while executing the query.")) { _log.Error("In Quickbooks Online something went wrong. It can't execute a simple query!!!"); } _log.Error($"Exception occured when application tried to recalculate sales tax in {EntityName} with id = {entityId}", e); throw; } }