SUBD_PIbd-21_Balberova_D.N./BeautySaloon/BeautySaloonBusinessLogic/OrderLogic.cs

88 lines
2.6 KiB
C#
Raw Normal View History

2023-03-28 17:32:55 +04:00
using BeautySaloonContracts.BindingModels;
using BeautySaloonContracts.BusinessLogicsContracts;
using BeautySaloonContracts.SearchModels;
using BeautySaloonContracts.StoragesContracts;
using BeautySaloonContracts.ViewModels;
namespace BeautySaloonBusinessLogic
{
public class OrderLogic : IOrderLogic
{
private readonly IOrderStorage _orderStorage;
public OrderLogic(IOrderStorage orderStorage)
{
_orderStorage = orderStorage;
}
public bool CreateOrder(OrderBindingModel model)
{
CheckModel(model);
if (_orderStorage.Insert(model) == null)
{
return false;
}
return true;
}
2023-03-29 20:00:53 +04:00
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;
}
2023-03-28 17:32:55 +04:00
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
{
var list = model == null ? _orderStorage.GetFullList() :
_orderStorage.GetFilteredList(model);
if (list == null)
{
return null;
}
return list;
}
2023-03-29 20:00:53 +04:00
public bool Update(OrderBindingModel model)
{
CheckModel(model);
if (_orderStorage.Update(model) == null)
{
return false;
}
return true;
}
2023-03-28 17:32:55 +04:00
private void CheckModel(OrderBindingModel model, bool withParams = true)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}
if (!withParams)
{
return;
}
if (model.Sum <= 0)
{
throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum));
}
if (model.ClientId <= 0)
{
throw new ArgumentNullException("Некорректный идентификатор клиента",
nameof(model.ClientId));
}
if (model.EmployeeId <= 0)
{
throw new ArgumentNullException("Некорректный идентификатор сотрудника",
nameof(model.ClientId));
}
}
}
}