using Contracts.BindingModels; using Contracts.BuisnessLogicsContracts; using Contracts.SearchModels; using Contracts.StorageContracts; using Contracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace BuisnessLogic { public class TypeLogic : ITypeLogic { ITypeStorage _typeStorage; public TypeLogic(ITypeStorage typeStorage) { _typeStorage = typeStorage; } public bool Create(TypeBindingModel model) { CheckModel(model); if (_typeStorage.Insert(model) == null) { return false; } return true; } public bool Delete(TypeBindingModel model) { CheckModel(model, false); if (_typeStorage.Delete(model) == null) { return false; } return true; } public TypeViewModel? ReadElement(TypeSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _typeStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(TypeSearchModel? model) { var list = model == null ? _typeStorage.GetFullList() : _typeStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public bool Update(TypeBindingModel model) { CheckModel(model); if (_typeStorage.Update(model) == null) { return false; } return true; } private void CheckModel(TypeBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } if (string.IsNullOrEmpty(model.PostType)) { throw new ArgumentNullException("Тип не указан", nameof(model.PostType)); } } } }