1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-03 00:52:49 -05:00

rename foles for subvault => collection

This commit is contained in:
Kyle Spearrin
2017-04-27 09:28:23 -04:00
parent b2bebda9ed
commit 755da8c38f
20 changed files with 0 additions and 0 deletions

View File

@ -0,0 +1,62 @@
using System;
using System.Threading.Tasks;
using Bit.Core.Exceptions;
using Bit.Core.Models.Table;
using Bit.Core.Repositories;
namespace Bit.Core.Services
{
public class CollectionService : ICollectionService
{
private readonly IOrganizationRepository _organizationRepository;
private readonly IOrganizationUserRepository _organizationUserRepository;
private readonly ICollectionRepository _collectionRepository;
private readonly ICollectionUserRepository _collectionUserRepository;
private readonly IUserRepository _userRepository;
private readonly IMailService _mailService;
public CollectionService(
IOrganizationRepository organizationRepository,
IOrganizationUserRepository organizationUserRepository,
ICollectionRepository collectionRepository,
ICollectionUserRepository collectionUserRepository,
IUserRepository userRepository,
IMailService mailService)
{
_organizationRepository = organizationRepository;
_organizationUserRepository = organizationUserRepository;
_collectionRepository = collectionRepository;
_collectionUserRepository = collectionUserRepository;
_userRepository = userRepository;
_mailService = mailService;
}
public async Task SaveAsync(Collection collection)
{
if(collection.Id == default(Guid))
{
var org = await _organizationRepository.GetByIdAsync(collection.OrganizationId);
if(org == null)
{
throw new BadRequestException("Org not found");
}
if(org.MaxCollections.HasValue)
{
var collectionCount = await _collectionRepository.GetCountByOrganizationIdAsync(org.Id);
if(org.MaxCollections.Value <= collectionCount)
{
throw new BadRequestException("You have reached the maximum number of collections " +
$"({org.MaxCollections.Value}) for this organization.");
}
}
await _collectionRepository.CreateAsync(collection);
}
else
{
await _collectionRepository.ReplaceAsync(collection);
}
}
}
}