1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-02 00:22:50 -05:00

Added cipher service with bulk import to account controller

This commit is contained in:
Kyle Spearrin
2015-12-26 23:09:53 -05:00
parent 437b971003
commit 8d7178bc74
14 changed files with 246 additions and 29 deletions

View File

@ -0,0 +1,54 @@
using System;
using System.Linq;
using System.Collections.Generic;
using System.Threading.Tasks;
using Bit.Core.Domains;
using Bit.Core.Repositories;
namespace Bit.Core.Services
{
public class CipherService : ICipherService
{
private readonly IFolderRepository _folderRepository;
private readonly ICipherRepository _cipherRepository;
public CipherService(
IFolderRepository folderRepository,
ICipherRepository cipherRepository)
{
_folderRepository = folderRepository;
_cipherRepository = cipherRepository;
}
public async Task ImportCiphersAsync(
List<Folder> folders,
List<Site> sites,
IEnumerable<KeyValuePair<int, int>> siteRelationships)
{
// create all the folders
var folderTasks = new List<Task>();
foreach(var folder in folders)
{
folderTasks.Add(_folderRepository.CreateAsync(folder));
}
await Task.WhenAll(folderTasks);
// associate the newly created folders to the sites
foreach(var relationship in siteRelationships)
{
var site = sites.ElementAtOrDefault(relationship.Key);
var folder = folders.ElementAtOrDefault(relationship.Value);
if(site == null || folder == null)
{
continue;
}
site.FolderId = folder.Id;
}
// create all the sites
await _cipherRepository.CreateAsync(sites);
}
}
}

View File

@ -0,0 +1,11 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Bit.Core.Domains;
namespace Bit.Core.Services
{
public interface ICipherService
{
Task ImportCiphersAsync(List<Folder> folders, List<Site> sites, IEnumerable<KeyValuePair<int, int>> siteRelationships);
}
}