PIbd-42_Kashin_M.I_CPO_Cour.../EmployeeManagmentBusinessLogic/BusinessLogic/EmployeeLogic.cs

68 lines
2.0 KiB
C#
Raw Normal View History

using EmployeeManagmentContracts.BusinessLogicContracts;
using EmployeeManagmentContracts.SearchModels;
using EmployeeManagmentContracts.StoragesContracts;
using EmployeeManagmentContracts.ViewModels;
using Microsoft.Extensions.Logging;
namespace EmployeeManagmentBusinessLogic.BusinessLogic
{
public class EmployeeLogic : IEmployeeLogic
{
private readonly ILogger<EmployeeLogic> _logger;
private readonly IEmployeeStorage _employeeStorage;
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
{
_logger = logger;
_employeeStorage = employeeStorage;
}
public List<EmployeeViewModel> GetFullList()
{
return _employeeStorage.GetFullList();
}
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
{
return _employeeStorage.GetFilteredList(model);
}
public EmployeeViewModel? GetElement(int id)
{
return _employeeStorage.GetElement(id);
}
public void Insert(EmployeeViewModel model)
{
if (string.IsNullOrWhiteSpace(model.NameJob))
{
throw new ArgumentException("Название должности обязательно для заполнения.");
}
_employeeStorage.Insert(model);
}
public void Update(EmployeeViewModel model)
{
var element = _employeeStorage.GetElement(model.Id);
if (element == null)
{
throw new ArgumentException("Сотрудник не найден.");
}
_employeeStorage.Update(model);
}
public void Delete(int id)
{
var element = _employeeStorage.GetElement(id);
if (element == null)
{
throw new ArgumentException("Сотрудник не найден.");
}
_employeeStorage.Delete(id);
}
}
}