2025-09-22 13:08:08 +02:00
|
|
|
using Models;
|
|
|
|
|
using Repository;
|
|
|
|
|
|
|
|
|
|
namespace Logic;
|
|
|
|
|
|
|
|
|
|
public class PasswordStoreService : IPasswordStoreService
|
|
|
|
|
{
|
|
|
|
|
private readonly IRepository repository;
|
2025-10-28 11:36:13 +01:00
|
|
|
private readonly ISecretService secretService;
|
2025-09-22 13:08:08 +02:00
|
|
|
|
2025-10-28 11:36:13 +01:00
|
|
|
public PasswordStoreService(IRepository repository, ISecretService secretService)
|
2025-09-30 11:31:38 +02:00
|
|
|
{
|
|
|
|
|
this.repository = repository;
|
2025-10-28 11:36:13 +01:00
|
|
|
this.secretService = secretService;
|
2025-09-30 11:31:38 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 15:35:31 +02:00
|
|
|
public void Create(PasswordStore item)
|
2025-09-22 13:08:08 +02:00
|
|
|
{
|
2025-10-28 11:36:13 +01:00
|
|
|
secretService.CreateCollection(item.DisplayName ?? item.Path);
|
2025-09-30 10:41:12 +02:00
|
|
|
repository.Create(item);
|
2025-09-22 13:08:08 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 15:35:31 +02:00
|
|
|
public void Delete(uint ID)
|
2025-09-22 13:08:08 +02:00
|
|
|
{
|
2025-09-30 10:41:12 +02:00
|
|
|
repository.Delete(ID);
|
2025-09-22 13:08:08 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 15:35:31 +02:00
|
|
|
public void Delete(PasswordStore item)
|
2025-09-22 13:08:08 +02:00
|
|
|
{
|
2025-09-22 15:35:31 +02:00
|
|
|
Delete(item.ID);
|
2025-09-22 13:08:08 +02:00
|
|
|
}
|
|
|
|
|
|
2025-09-22 15:35:31 +02:00
|
|
|
public void Edit(uint ID, PasswordStore newItem)
|
2025-09-22 13:08:08 +02:00
|
|
|
{
|
2025-09-30 10:41:12 +02:00
|
|
|
repository.Delete(ID);
|
|
|
|
|
newItem.ID = ID;
|
|
|
|
|
repository.Create(newItem);
|
2025-09-22 13:08:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public PasswordStore Get(uint ID)
|
|
|
|
|
{
|
2025-09-30 10:41:12 +02:00
|
|
|
return repository.GetAll().FirstOrDefault(i => i.ID == ID) ?? throw new Exception("Item not found");
|
2025-09-22 13:08:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<PasswordStore> GetAll()
|
|
|
|
|
{
|
2025-09-30 10:41:12 +02:00
|
|
|
return repository.GetAll();
|
2025-09-22 13:08:08 +02:00
|
|
|
}
|
|
|
|
|
}
|