using SushiBarContracts.BindingModels; using SushiBarContracts.BusinessLogicContracts; using SushiBarContracts.SearchModels; using SushiBarContracts.StoragesContracts; using SushiBarContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace SushiBarBusinessLogic.BusinessLogics { public class CookLogic : ICookLogic { private readonly ICookStorage _cookStorage; public CookLogic(ICookStorage cookStorage) { _cookStorage = cookStorage; } public CookViewModel? ReadElement(CookSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _cookStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(CookSearchModel? model) { var list = model == null ? _cookStorage.GetFullList() : _cookStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public bool Create(CookBindingModel model) { CheckModel(model); if (_cookStorage.Insert(model) == null) { return false; } return true; } public bool Delete(CookBindingModel model) { CheckModel(model, false); if (_cookStorage.Delete(model) == null) { return false; } return true; } public bool Update(CookBindingModel model) { CheckModel(model); if (_cookStorage.Update(model) == null) { return false; } return true; } private void CheckModel(CookBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } if (string.IsNullOrEmpty(model.CookName)) { throw new ArgumentNullException("Нет названия", nameof(model.CookName)); } } } }