private void DoWork(ExerciseTypeImportDto row, ParallelLoopState loopState)
        {
            // parse all tags and tag groups and assign exercise properties (join table entity) on exercise type
            var properties = new List <ExerciseTypeTag>();

            if (!string.IsNullOrWhiteSpace(row.Tags) && !string.IsNullOrWhiteSpace(row.TagGroups))
            {
                properties = ParseExerciseTypeProperties(row.TagGroups, row.Tags).ToList();
            }

            // parse and get exercise type from data row
            ParseExerciseType(row, properties);
        }
        private void ParseExerciseType(ExerciseTypeImportDto row, List <ExerciseTypeTag> properties)
        {
            _existingTypes.TryGetValue(row.Code, out var existingType);

            var type = _mapper.Map <ExerciseType>(row);

            if (existingType != null)
            {
                type = existingType;

                type.ApplicationUserId = _userId;

                // remove existing properties
                foreach (var property in existingType.Properties)
                {
                    //_context.Entry(property).State = EntityState.Deleted;
                    _context.ExerciseTypeTags.Remove(property);
                }

                // assign new properties
                type.Properties            = properties;
                _context.Entry(type).State = EntityState.Modified;

                foreach (var property in type.Properties)
                {
                    property.ExerciseTypeId        = type.Id;
                    _context.Entry(property).State = EntityState.Added;
                }
                //_context.Entry(type).State = EntityState.Modified;
            }
            else
            {
                type.Id = Guid.NewGuid();

                type.ApplicationUserId     = _userId;
                type.Properties            = properties;
                _context.Entry(type).State = EntityState.Added;

                foreach (var property in type.Properties)
                {
                    property.ExerciseTypeId        = type.Id;
                    _context.Entry(property).State = EntityState.Added;
                }
                //_context.Entry(type).State = EntityState.Added;
                _context.ExerciseTypes.Add(type);
            }

            _existingTypes.AddOrUpdate(type.Code, (id) => type, (id, item) => type);
        }