private static void AddAssetsToGroups(IEnumerable <string> assetIds, IEnumerable <string> groups) { ResetOutputCounter(); Console.ResetColor(); Console.WriteLine("Adding assets to groups..."); var assetsInGroups = groups.ToDictionary(x => x, x => _assetsService.AssetGroupGetAssetIds(x)); Parallel.ForEach(assetIds, assetId => { var operationResult = ""; var operationSucceeded = true; try { foreach (var groupToAssign in assetsInGroups.Keys) { if (!assetsInGroups[groupToAssign].Contains(assetId)) { _assetsService.AssetGroupAddAsset(assetId, groupToAssign); } } operationResult = "added to specified groups"; } catch (Exception e) { operationResult = e.ToOperationResult(); operationSucceeded = false; } OutputOperationResult(assetId, operationResult, operationSucceeded); }); }