Files
PIbd-31_Egorov_M.A._COP_34/Components/BusinessLogic/BusinessLogic/DepartmentTypeLogic.cs
2025-09-05 16:30:40 +04:00

94 lines
2.6 KiB
C#

using Contracts.BindingModels;
using Contracts.BusinessLogicContracts;
using Contracts.SearchModels;
using Contracts.StorageContracts;
using Contracts.ViewModels;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace BusinessLogic.BusinessLogic
{
public class DepartmentTypeLogic : IDepartmentTypeLogic
{
private readonly IDepartmentTypeStorage _orgTypeStorage;
public DepartmentTypeLogic(IDepartmentTypeStorage orgTypeStorage)
{
_orgTypeStorage = orgTypeStorage;
}
public List<DepartmentTypeViewModel>? ReadList(DepartmentTypeSearchModel? model)
{
var list = model == null ? _orgTypeStorage.GetFullList() : _orgTypeStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
public DepartmentTypeViewModel? ReadElement(DepartmentTypeSearchModel? model)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
var element = _orgTypeStorage.GetElement(model);
if (element == null)
{
return null;
}
return element;
}
public bool Create(DepartmentTypeBindingModel model)
{
CheckModel(model);
if (_orgTypeStorage.Insert(model) == null)
{
return false;
}
return true;
}
public bool Update(DepartmentTypeBindingModel model)
{
CheckModel(model);
if (_orgTypeStorage.Update(model) == null)
{
return false;
}
return true;
}
public bool Delete(DepartmentTypeBindingModel model)
{
CheckModel(model, false);
if (_orgTypeStorage.Delete(model) == null)
{
return false;
}
return true;
}
private void CheckModel(DepartmentTypeBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (string.IsNullOrEmpty(model.Name))
{
throw new ArgumentException("Введите название доставки", nameof(model.Name));
}
}
}
}