64 lines
2.0 KiB
C#
64 lines
2.0 KiB
C#
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;
|
|
}
|
|
|
|
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
|
{
|
|
var list = model == null ? _orderStorage.GetFullList() :
|
|
_orderStorage.GetFilteredList(model);
|
|
if (list == null)
|
|
{
|
|
return null;
|
|
}
|
|
return list;
|
|
}
|
|
|
|
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));
|
|
}
|
|
}
|
|
}
|
|
}
|