Sample code to populate value for taxclass Id

This demo sample code will try to get all taxclasses that does not have Id and then generate a unique id for those.

The sample file could be download here and could be put in Utilities folder of Litium.Accelerator project: 

Taxclass setup.PNG

internal class TaxClassIdSetup : IStartupTask
    {
        private readonly TaxClassService _taxClassService;
        private readonly DataService _dataService;
        private readonly SecurityContextService _securityContextService;

        public TaxClassIdSetup(TaxClassService taxClassService, DataService dataService, SecurityContextService securityContextService)
        {
            _taxClassService = taxClassService;
            _dataService = dataService;
            _securityContextService = securityContextService;
        }
        public void Start()
        {
            var taxClassToUpdate = _taxClassService.GetAll().Where(x => string.IsNullOrEmpty(x.Id)).Select(x => x.MakeWritableClone());
            if (!taxClassToUpdate.Any())
            {
                return;
            }
            using var batch = _dataService.CreateBatch();
            using (_securityContextService.ActAsSystem("TaxclassId setup."))
            {
                foreach (var taxClass in taxClassToUpdate)
                {
                    taxClass.Id = GenerateTaxclassId(taxClass.SystemId);
                    batch.Update(taxClass);
                }
                batch.Commit();
            }
        }

        private string GenerateTaxclassId(Guid systemId)
        {
            var s = systemId.ToString();
            return $"taxclass_{s.Substring(s.Length - 4)}";
        }
    }

Updated data after task run : 

updatedTaxClass.PNG