2024-12-01 17:14:10 +04:00
|
|
|
|
using EmployeeManagmentContracts.BusinessLogicContracts;
|
2024-11-12 21:25:53 +04:00
|
|
|
|
using EmployeeManagmentContracts.SearchModels;
|
|
|
|
|
using EmployeeManagmentContracts.ViewModels;
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using EmployeeManagmentContracts.StoragesContracts;
|
2024-11-26 22:35:12 +04:00
|
|
|
|
using Microsoft.Extensions.Logging;
|
2024-12-01 17:14:10 +04:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2024-11-12 13:07:37 +04:00
|
|
|
|
|
|
|
|
|
namespace EmployeeManagmentBusinessLogic.BusinessLogic
|
|
|
|
|
{
|
|
|
|
|
public class VacationLogic : IVacationLogic
|
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
private readonly ILogger<VacationLogic> _logger;
|
2024-11-26 22:35:12 +04:00
|
|
|
|
private readonly IVacationStorage _vacationStorage;
|
|
|
|
|
|
|
|
|
|
public VacationLogic(ILogger<VacationLogic> logger, IVacationStorage vacationStorage)
|
2024-11-12 13:07:37 +04:00
|
|
|
|
{
|
2024-11-26 22:35:12 +04:00
|
|
|
|
_logger = logger;
|
|
|
|
|
_vacationStorage = vacationStorage;
|
2024-11-12 13:07:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public List<VacationViewModel> GetFullList()
|
2024-11-12 13:07:37 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
return _vacationStorage.GetFullList();
|
2024-11-12 13:07:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public List<VacationViewModel> GetFilteredList(VacationSearchModel model)
|
2024-11-26 22:35:12 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
return _vacationStorage.GetFilteredList(model);
|
2024-11-26 22:35:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public VacationViewModel? GetElement(int id)
|
2024-11-26 22:35:12 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
return _vacationStorage.GetElement(id);
|
2024-11-26 22:35:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public void Insert(VacationViewModel model)
|
2024-11-26 22:35:12 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
if (model.EmployeeId == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Сотрудник обязательно должен быть указан.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_vacationStorage.Insert(model);
|
2024-11-26 22:35:12 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public void Update(VacationViewModel model)
|
2024-11-12 13:07:37 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
var element = _vacationStorage.GetElement(model.Id);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Отпуск не найден.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_vacationStorage.Update(model);
|
2024-11-12 13:07:37 +04:00
|
|
|
|
}
|
|
|
|
|
|
2024-12-01 17:14:10 +04:00
|
|
|
|
public void Delete(int id)
|
2024-11-12 13:07:37 +04:00
|
|
|
|
{
|
2024-12-01 17:14:10 +04:00
|
|
|
|
var element = _vacationStorage.GetElement(id);
|
|
|
|
|
if (element == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentException("Отпуск не найден.");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_vacationStorage.Delete(id);
|
2024-11-12 13:07:37 +04:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|