PIbd-22_Shabunov_O.A._SushiBar/SushiBarBusinessLogic/CookLogic.cs
2024-05-16 17:26:24 +04:00

70 lines
1.6 KiB
C#

using SushiBarContracts.BindingModels;
using SushiBarContracts.SearchModels;
using SushiBarContracts.ViewModels;
using SushiBarDatabaseImplement.Storages;
namespace SushiBarBusinessLogic
{
public class CookLogic
{
private readonly CookStorage _cookStorage;
public CookLogic(CookStorage CookStorage)
{
_cookStorage = CookStorage;
}
public List<CookViewModel>? ReadList(CookSearchModel? Model)
{
var List = Model is null ? _cookStorage.GetFullList() : _cookStorage.GetFilteredList(Model);
if (List is null)
{
return null;
}
return List;
}
public CookViewModel? ReadElement(CookSearchModel? Model)
{
if (Model is null)
throw new ArgumentNullException(nameof(Model));
var Element = _cookStorage.GetElement(Model);
if (Element is null)
{
return null;
}
return Element;
}
public bool Create(CookBindingModel Model)
{
if (_cookStorage.Insert(Model) is null)
{
return false;
}
return true;
}
public bool Update(CookBindingModel Model)
{
if (_cookStorage.Update(Model) is null)
{
return false;
}
return true;
}
public bool Delete(CookBindingModel Model)
{
if (_cookStorage.Delete(Model) is null)
{
return false;
}
return true;
}
}
}