Rework so employee dont use repos but servies

This commit is contained in:
Alex Pedersen
2026-07-30 10:23:27 +02:00
parent 6df185d519
commit 9497afe262
26 changed files with 630 additions and 125 deletions

View File

@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Linq;
using Database.Models;
using Database.Repository;
namespace Pos.Service
{
public class ProductGroupService
{
private readonly ProductGroupRepository _productGroupRepository =
new ProductGroupRepository();
public List<ProductGroupEntity> GetProductGroups()
{
return _productGroupRepository.GetAll();
}
public bool HasProductGroups()
{
return _productGroupRepository.Any();
}
public void AddProductGroup(string name)
{
_productGroupRepository.Add(ValidateName(name));
CacheService.Invalidate();
}
public void RenameProductGroup(int productGroupId, string name)
{
ValidateId(productGroupId);
_productGroupRepository.Edit(
ValidateName(name),
productGroupId);
CacheService.Invalidate();
}
public void ArchiveProductGroup(int productGroupId)
{
ValidateId(productGroupId);
_productGroupRepository.Archive(productGroupId);
CacheService.Invalidate();
}
public void UpdateOrder(IReadOnlyList<int> orderedProductGroupIds)
{
ValidateOrder(orderedProductGroupIds);
_productGroupRepository.SetOrder(orderedProductGroupIds);
CacheService.Invalidate();
}
private static string ValidateName(string name)
{
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentException(
"Produktgruppen skal have et navn.",
nameof(name));
return name.Trim();
}
private static void ValidateId(int productGroupId)
{
if (productGroupId <= 0)
throw new ArgumentOutOfRangeException(nameof(productGroupId));
}
private static void ValidateOrder(IReadOnlyList<int> orderedIds)
{
if (orderedIds == null)
throw new ArgumentNullException(nameof(orderedIds));
if (orderedIds.Any(id => id <= 0))
throw new ArgumentException(
"Rækkefølgen indeholder et ugyldigt id.",
nameof(orderedIds));
if (orderedIds.Distinct().Count() != orderedIds.Count)
throw new ArgumentException(
"Rækkefølgen indeholder dubletter.",
nameof(orderedIds));
}
}
}