PIbd-22_Shabunov_O.A._SushiBar/SushiBarBusinessLogic/DishLogic.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 DishLogic
{
private readonly DishStorage _dishStorage;
public DishLogic(DishStorage DishStorage)
{
_dishStorage = DishStorage;
}
public List<DishViewModel>? ReadList(DishSearchModel? Model)
{
var List = Model is null ? _dishStorage.GetFullList() : _dishStorage.GetFilteredList(Model);
if (List is null)
{
return null;
}
return List;
}
public DishViewModel? ReadElement(DishSearchModel? Model)
{
if (Model is null)
throw new ArgumentNullException(nameof(Model));
var Element = _dishStorage.GetElement(Model);
if (Element is null)
{
return null;
}
return Element;
}
public bool Create(DishBindingModel Model)
{
if (_dishStorage.Insert(Model) is null)
{
return false;
}
return true;
}
public bool Update(DishBindingModel Model)
{
if (_dishStorage.Update(Model) is null)
{
return false;
}
return true;
}
public bool Delete(DishBindingModel Model)
{
if (_dishStorage.Delete(Model) is null)
{
return false;
}
return true;
}
}
}