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 TaskLogic : ITaskLogic { private readonly ITaskStorage _taskStorage; public TaskLogic(ITaskStorage taskStorage) { _taskStorage = taskStorage; } public TaskViewModel? ReadElement(TaskSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _taskStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(TaskSearchModel? model) { var list = model == null ? _taskStorage.GetFullList() : _taskStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public bool Create(TaskBindingModel model) { CheckModel(model); if (_taskStorage.Insert(model) == null) { return false; } return true; } public bool Delete(TaskBindingModel model) { CheckModel(model, false); if (_taskStorage.Delete(model) == null) { return false; } return true; } public bool Update(TaskBindingModel model) { CheckModel(model); if (_taskStorage.Update(model) == null) { return false; } return true; } private void CheckModel(TaskBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } } } }