91 lines
2.2 KiB
C#
91 lines
2.2 KiB
C#
using DatabaseImplement.Implements;
|
|
using DataContracts.bindingModels;
|
|
using DataContracts.BLs;
|
|
using DataContracts.searchModels;
|
|
using DataContracts.viewModels;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BusinessLogic
|
|
{
|
|
public class ProductBL : IProductBL
|
|
{
|
|
private readonly ProductStorage _productStorage = new();
|
|
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 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()
|
|
{
|
|
var list = _productStorage.GetFullList();
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
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.title))
|
|
{
|
|
throw new ArgumentNullException("Нет имени клиента", nameof(model.title));
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
}
|