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

70 lines
2.0 KiB
C#

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 SalaryLogic : ISalaryLogic
{
private readonly ILogger<SalaryLogic> _logger;
private readonly ISalaryStorage _salaryStorage;
public SalaryLogic(ILogger<SalaryLogic> logger, ISalaryStorage salaryStorage)
{
_logger = logger;
_salaryStorage = salaryStorage;
}
public List<SalaryViewModel> GetFullList()
{
return _salaryStorage.GetFullList();
}
public List<SalaryViewModel> GetFilteredList(SalarySearchModel model)
{
return _salaryStorage.GetFilteredList(model);
}
public SalaryViewModel? GetElement(int id)
{
return _salaryStorage.GetElement(id);
}
public void Insert(SalaryViewModel model)
{
if (model.EmployeeId == null)
{
throw new ArgumentException("Сотрудник обязательно должен быть указан.");
}
_salaryStorage.Insert(model);
}
public void Update(SalaryViewModel model)
{
var element = _salaryStorage.GetElement(model.Id);
if (element == null)
{
throw new ArgumentException("Зарплата не найдена.");
}
_salaryStorage.Update(model);
}
public void Delete(int id)
{
var element = _salaryStorage.GetElement(id);
if (element == null)
{
throw new ArgumentException("Зарплата не найдена.");
}
_salaryStorage.Delete(id);
}
}
}