Rework so employee dont use repos but servies
This commit is contained in:
54
PointOfSale/Pos.Service/EmployeeService.cs
Normal file
54
PointOfSale/Pos.Service/EmployeeService.cs
Normal file
@@ -0,0 +1,54 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Database.Models;
|
||||
using Database.Repository;
|
||||
|
||||
namespace Pos.Service
|
||||
{
|
||||
public class EmployeeService
|
||||
{
|
||||
private readonly EmployeeRepository _employeeRepository =
|
||||
new EmployeeRepository();
|
||||
|
||||
public List<EmployeeEntity> GetEmployees()
|
||||
{
|
||||
return _employeeRepository.GetAll();
|
||||
}
|
||||
|
||||
public void AddEmployee(string name)
|
||||
{
|
||||
_employeeRepository.Add(ValidateName(name));
|
||||
CacheService.Invalidate();
|
||||
}
|
||||
|
||||
public void RenameEmployee(int employeeId, string name)
|
||||
{
|
||||
ValidateId(employeeId);
|
||||
_employeeRepository.Edit(employeeId, ValidateName(name));
|
||||
CacheService.Invalidate();
|
||||
}
|
||||
|
||||
public void ArchiveEmployee(int employeeId)
|
||||
{
|
||||
ValidateId(employeeId);
|
||||
_employeeRepository.Delete(employeeId);
|
||||
CacheService.Invalidate();
|
||||
}
|
||||
|
||||
private static string ValidateName(string name)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(name))
|
||||
throw new ArgumentException(
|
||||
"Medarbejderens navn skal være udfyldt.",
|
||||
nameof(name));
|
||||
|
||||
return name.Trim();
|
||||
}
|
||||
|
||||
private static void ValidateId(int employeeId)
|
||||
{
|
||||
if (employeeId <= 0)
|
||||
throw new ArgumentOutOfRangeException(nameof(employeeId));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user