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

70 lines
1.8 KiB
C#

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