Bit.Core.Services.CipherService.ImportCiphersAsync C# (CSharp) Method

ImportCiphersAsync() public method

public ImportCiphersAsync ( List folders, List ciphers, int>.IEnumerable folderRelationships ) : System.Threading.Tasks.Task
folders List
ciphers List
folderRelationships int>.IEnumerable
return System.Threading.Tasks.Task
        public async Task ImportCiphersAsync(
            List<Cipher> folders,
            List<Cipher> ciphers,
            IEnumerable<KeyValuePair<int, int>> folderRelationships)
        {
            // create all the folders
            var folderTasks = new List<Task>();
            foreach(var folder in folders)
            {
                folderTasks.Add(_cipherRepository.CreateAsync(folder));
            }
            await Task.WhenAll(folderTasks);

            // associate the newly created folders to the ciphers
            foreach(var relationship in folderRelationships)
            {
                var cipher = ciphers.ElementAtOrDefault(relationship.Key);
                var folder = folders.ElementAtOrDefault(relationship.Value);

                if(cipher == null || folder == null)
                {
                    continue;
                }

                cipher.FolderId = folder.Id;
            }

            // create all the ciphers
            await _cipherRepository.CreateAsync(ciphers);

            // push
            var userId = folders.FirstOrDefault()?.UserId ?? ciphers.FirstOrDefault()?.UserId;
            if(userId.HasValue)
            {
                await _pushService.PushSyncCiphersAsync(userId.Value);
            }
        }
    }