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 MenuLogic : IMenuLogic { private readonly IMenuStorage _menuStorage; public MenuLogic(IMenuStorage menuStorage) { _menuStorage = menuStorage; } public MenuViewModel? ReadElement(MenuSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _menuStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(MenuSearchModel? model) { var list = model == null ? _menuStorage.GetFullList() : _menuStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public bool Create(MenuBindingModel model) { CheckModel(model); if (_menuStorage.Insert(model) == null) { return false; } return true; } public bool Delete(MenuBindingModel model) { CheckModel(model, false); if (_menuStorage.Delete(model) == null) { return false; } return true; } public bool Update(MenuBindingModel model) { CheckModel(model); if (_menuStorage.Update(model) == null) { return false; } return true; } private void CheckModel(MenuBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } if (string.IsNullOrEmpty(model.FoodName)) { throw new ArgumentNullException("Нет названия", nameof(model.FoodName)); } } } }