99 lines
2.6 KiB
C#
99 lines
2.6 KiB
C#
using Subd_4.BindingModels;
|
|
using Subd_4.BusinessLogicContracts;
|
|
using Subd_4.SearchModels;
|
|
using Subd_4.StoragesContracts;
|
|
using Subd_4.ViewModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace ConstructionFirmBusinessLogic.BusinessLogics
|
|
{
|
|
public class EmployeeLogic : IEmployeeLogic
|
|
{
|
|
private readonly IEmployeeStorage _EmployeeStorage;
|
|
|
|
public EmployeeLogic(IEmployeeStorage employeeStorage)
|
|
{
|
|
_EmployeeStorage = employeeStorage;
|
|
}
|
|
public EmployeeViewModel? ReadElement(EmployeeSearchModel model)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
|
|
var element = _EmployeeStorage.GetElement(model);
|
|
if (element == null)
|
|
{
|
|
return null;
|
|
}
|
|
return element;
|
|
}
|
|
|
|
public List<EmployeeViewModel>? ReadList(EmployeeSearchModel? model)
|
|
{
|
|
var list = model == null ? _EmployeeStorage.GetFullList() : _EmployeeStorage.GetFilteredList(model);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
public bool Create(EmployeeBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_EmployeeStorage.Insert(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Delete(EmployeeBindingModel model)
|
|
{
|
|
CheckModel(model, false);
|
|
if (_EmployeeStorage.Delete(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
public bool Update(EmployeeBindingModel model)
|
|
{
|
|
CheckModel(model);
|
|
if (_EmployeeStorage.Update(model) == null)
|
|
{
|
|
return false;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
private void CheckModel(EmployeeBindingModel model, bool withParams = true)
|
|
{
|
|
if (model == null)
|
|
{
|
|
throw new ArgumentNullException(nameof(model));
|
|
}
|
|
if (!withParams)
|
|
{
|
|
return;
|
|
}
|
|
if (string.IsNullOrEmpty(model.FullName))
|
|
{
|
|
throw new ArgumentNullException("Нет названия", nameof(model.FullName));
|
|
}
|
|
}
|
|
|
|
public void ClearEntity()
|
|
{
|
|
_EmployeeStorage.ClearEntity();
|
|
}
|
|
}
|
|
}
|