Создание слоя бизнес логики
This commit is contained in:
parent
948d0515be
commit
9e6dab9f5f
@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountingWarehouseProducts
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountingWarehouseProductsContracts", "AccountingWarehouseProductsContracts\AccountingWarehouseProductsContracts.csproj", "{4633456D-A979-41D6-9D0A-A6DAA6A17766}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountingWarehouseProductsContracts", "AccountingWarehouseProductsContracts\AccountingWarehouseProductsContracts.csproj", "{4633456D-A979-41D6-9D0A-A6DAA6A17766}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AccountingWarehouseProductsBusinessLogic", "AccountingWarehouseProductsBusinessLogic\AccountingWarehouseProductsBusinessLogic.csproj", "{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
Debug|Any CPU = Debug|Any CPU
|
Debug|Any CPU = Debug|Any CPU
|
||||||
@ -27,6 +29,10 @@ Global
|
|||||||
{4633456D-A979-41D6-9D0A-A6DAA6A17766}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{4633456D-A979-41D6-9D0A-A6DAA6A17766}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{4633456D-A979-41D6-9D0A-A6DAA6A17766}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{4633456D-A979-41D6-9D0A-A6DAA6A17766}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{4633456D-A979-41D6-9D0A-A6DAA6A17766}.Release|Any CPU.Build.0 = Release|Any CPU
|
{4633456D-A979-41D6-9D0A-A6DAA6A17766}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{7F90D2FA-8F89-4200-92FC-CFFF489AD6C9}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
@ -0,0 +1,13 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>net6.0</TargetFramework>
|
||||||
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
|
<Nullable>enable</Nullable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\AccountingWarehouseProductsContracts\AccountingWarehouseProductsContracts.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
@ -0,0 +1,136 @@
|
|||||||
|
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 OrderLogic : IOrderLogic
|
||||||
|
{
|
||||||
|
private readonly IOrderStorage _orderStorage;
|
||||||
|
|
||||||
|
public OrderLogic(IOrderStorage orderStorage)
|
||||||
|
{
|
||||||
|
_orderStorage = orderStorage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OrderViewModel? ReadElement(OrderSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
var element = _orderStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||||||
|
{
|
||||||
|
var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_orderStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
if (_orderStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool OrderedOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Заказан);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ComeOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Пришёл);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool TakeOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Принят);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ArrangeOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Расстановлен);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ChekOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Проверен);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool DeliverOrder(OrderBindingModel model)
|
||||||
|
{
|
||||||
|
return StatusUpdate(model, AccountingWarehouseProductsDataModels.Enums.OrderStatus.Доставлен);
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool StatusUpdate(OrderBindingModel model, AccountingWarehouseProductsDataModels.Enums.OrderStatus newStatus)
|
||||||
|
{
|
||||||
|
|
||||||
|
if (model.Status + 1 != newStatus)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
model.Status = newStatus;
|
||||||
|
if (_orderStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
model.Status--;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
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 ProductLogic : IProductLogic
|
||||||
|
{
|
||||||
|
private readonly IProductStorage _productStorage;
|
||||||
|
|
||||||
|
public ProductLogic(IProductStorage buyerStorage)
|
||||||
|
{
|
||||||
|
_productStorage = buyerStorage;
|
||||||
|
}
|
||||||
|
public ProductViewModel? ReadElement(ProductSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
var element = _productStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ProductViewModel>? ReadList(ProductSearchModel? model)
|
||||||
|
{
|
||||||
|
var list = model == null ? _productStorage.GetFullList() : _productStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_productStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
if (_productStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ProductBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_productStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(ProductBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.ProductName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия", nameof(model.ProductName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
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 ShipmentLogic : IShipmentLogic
|
||||||
|
{
|
||||||
|
private readonly IShipmentStorage _shipmentStorage;
|
||||||
|
|
||||||
|
public ShipmentLogic(IShipmentStorage shipmentStorage)
|
||||||
|
{
|
||||||
|
_shipmentStorage = shipmentStorage;
|
||||||
|
}
|
||||||
|
public ShipmentViewModel? ReadElement(ShipmentSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
var element = _shipmentStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<ShipmentViewModel>? ReadList(ShipmentSearchModel? model)
|
||||||
|
{
|
||||||
|
var list = model == null ? _shipmentStorage.GetFullList() : _shipmentStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(ShipmentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_shipmentStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(ShipmentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
if (_shipmentStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(ShipmentBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_shipmentStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(ShipmentBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,89 @@
|
|||||||
|
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 StandLogic : IStandLogic
|
||||||
|
{
|
||||||
|
private readonly IStandStorage _standStorage;
|
||||||
|
|
||||||
|
public StandLogic(IStandStorage standStorage)
|
||||||
|
{
|
||||||
|
_standStorage = standStorage;
|
||||||
|
}
|
||||||
|
public StandViewModel? ReadElement(StandSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
var element = _standStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<StandViewModel>? ReadList(StandSearchModel? model)
|
||||||
|
{
|
||||||
|
var list = model == null ? _standStorage.GetFullList() : _standStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(StandBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_standStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(StandBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
if (_standStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(StandBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_standStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(StandBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
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<SupplierViewModel>? 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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
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 WarehouseLogic : IWarehouseLogic
|
||||||
|
{
|
||||||
|
private readonly IWarehouseStorage _warehouseStorage;
|
||||||
|
|
||||||
|
public WarehouseLogic(IWarehouseStorage warehouseStorage)
|
||||||
|
{
|
||||||
|
_warehouseStorage = warehouseStorage;
|
||||||
|
}
|
||||||
|
public WarehouseViewModel? ReadElement(WarehouseSearchModel model)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
|
||||||
|
var element = _warehouseStorage.GetElement(model);
|
||||||
|
if (element == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WarehouseViewModel>? ReadList(WarehouseSearchModel? model)
|
||||||
|
{
|
||||||
|
var list = model == null ? _warehouseStorage.GetFullList() : _warehouseStorage.GetFilteredList(model);
|
||||||
|
if (list == null)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Create(WarehouseBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_warehouseStorage.Insert(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Delete(WarehouseBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model, false);
|
||||||
|
if (_warehouseStorage.Delete(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Update(WarehouseBindingModel model)
|
||||||
|
{
|
||||||
|
CheckModel(model);
|
||||||
|
if (_warehouseStorage.Update(model) == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CheckModel(WarehouseBindingModel model, bool withParams = true)
|
||||||
|
{
|
||||||
|
if (model == null)
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException(nameof(model));
|
||||||
|
}
|
||||||
|
if (!withParams)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (string.IsNullOrEmpty(model.WarehouseName))
|
||||||
|
{
|
||||||
|
throw new ArgumentNullException("Нет названия", nameof(model.WarehouseName));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user