using AccountingWarehouseProductsContracts.BindingModels; using AccountingWarehouseProductsContracts.BusinessLogicsContracts; using AccountingWarehouseProductsContracts.SearchModels; using AccountingWarehouseProductsContracts.StoragesContracts; using AccountingWarehouseProductsContracts.ViewModels; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace AccountingWarehouseProductsBusinessLogic.BusinessLogic { public class SupplierLogic : ISupplierLogic { private readonly ISupplierStorage _supplierStorage; public SupplierLogic(ISupplierStorage supplierStorage) { _supplierStorage = supplierStorage; } public SupplierViewModel? ReadElement(SupplierSearchModel model) { if (model == null) { throw new ArgumentNullException(nameof(model)); } var element = _supplierStorage.GetElement(model); if (element == null) { return null; } return element; } public List? ReadList(SupplierSearchModel? model) { var list = model == null ? _supplierStorage.GetFullList() : _supplierStorage.GetFilteredList(model); if (list == null) { return null; } return list; } public bool Create(SupplierBindingModel model) { CheckModel(model); if (_supplierStorage.Insert(model) == null) { return false; } return true; } public bool Delete(SupplierBindingModel model) { CheckModel(model, false); if (_supplierStorage.Delete(model) == null) { return false; } return true; } public bool Update(SupplierBindingModel model) { CheckModel(model); if (_supplierStorage.Update(model) == null) { return false; } return true; } private void CheckModel(SupplierBindingModel model, bool withParams = true) { if (model == null) { throw new ArgumentNullException(nameof(model)); } if (!withParams) { return; } if (string.IsNullOrEmpty(model.SupplierName)) { throw new ArgumentNullException("Нет названия", nameof(model.SupplierName)); } } } }