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

70 lines
2.0 KiB
C#
Raw Normal View History

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