2024-12-01 14:29:10 +04:00
|
|
|
|
using EmployeeManagmentContracts.BusinessLogicContracts;
|
2024-11-12 21:25:53 +04:00
|
|
|
|
using EmployeeManagmentContracts.SearchModels;
|
2024-11-26 21:24:08 +04:00
|
|
|
|
using EmployeeManagmentContracts.StoragesContracts;
|
2024-11-12 21:25:53 +04:00
|
|
|
|
using EmployeeManagmentContracts.ViewModels;
|
2024-11-26 21:24:08 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-11-12 13:07:37 +04:00
|
|
|
|
|
|
|
|
|
namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class EmployeeLogic : IEmployeeLogic
|
|
|
|
|
{
|
2024-12-01 14:29:10 +04:00
|
|
|
|
private readonly ILogger<EmployeeLogic> _logger;
|
2024-11-26 21:24:08 +04:00
|
|
|
|
private readonly IEmployeeStorage _employeeStorage;
|
2024-11-13 14:41:01 +04:00
|
|
|
|
|
2024-11-26 21:24:08 +04:00
|
|
|
|
public EmployeeLogic(ILogger<EmployeeLogic> logger, IEmployeeStorage employeeStorage)
|
2024-11-13 14:41:01 +04:00
|
|
|
|
{
|
2024-11-26 21:24:08 +04:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_employeeStorage = employeeStorage;
|
2024-11-13 14:41:01 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 14:29:10 +04:00
|
|
|
|
public List<EmployeeViewModel> GetFullList()
|
2024-11-12 13:07:37 +04:00
|
|
|
|
{
|
2024-12-01 14:29:10 +04:00
|
|
|
|
return _employeeStorage.GetFullList();
|
2024-11-12 13:07:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-11-26 21:24:08 +04:00
|
|
|
|
public List<EmployeeViewModel> GetFilteredList(EmployeeSearchModel model)
|
2024-11-12 13:07:37 +04:00
|
|
|
|
{
|
2024-12-01 14:29:10 +04:00
|
|
|
|
return _employeeStorage.GetFilteredList(model);
|
2024-11-12 13:07:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 14:29:10 +04:00
|
|
|
|
public EmployeeViewModel? GetElement(int id)
|
2024-11-12 13:07:37 +04:00
|
|
|
|
{
|
2024-12-01 14:29:10 +04:00
|
|
|
|
return _employeeStorage.GetElement(id);
|
2024-11-26 21:24:08 +04:00
|
|
|
|
}
|
2024-11-13 14:41:01 +04:00
|
|
|
|
|
2024-11-26 21:24:08 +04:00
|
|
|
|
public void Insert(EmployeeViewModel model)
|
|
|
|
|
{
|
2024-12-01 14:29:10 +04:00
|
|
|
|
if (string.IsNullOrWhiteSpace(model.NameJob))
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Название должности обязательно для заполнения.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_employeeStorage.Insert(model);
|
2024-11-12 13:07:37 +04:00
|
|
|
|
}
|
2024-11-13 14:41:01 +04:00
|
|
|
|
|
2024-11-26 21:24:08 +04:00
|
|
|
|
public void Update(EmployeeViewModel model)
|
|
|
|
|
{
|
2024-12-01 14:29:10 +04:00
|
|
|
|
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);
|
2024-11-26 21:24:08 +04:00
|
|
|
|
}
|
2024-11-12 13:07:37 +04:00
|
|
|
|
}
|
|
|
|
|
}
|