96 lines
2.7 KiB
C#
96 lines
2.7 KiB
C#
using Contracts.BindingModels;
|
||
using Contracts.BusinessLogicContracts;
|
||
using Contracts.SearchModels;
|
||
using Contracts.StorageContracts;
|
||
using Contracts.ViewModels;
|
||
using System;
|
||
|
||
namespace BusinessLogic
|
||
{
|
||
public class OrderLogic : IOrderLogic
|
||
{
|
||
|
||
IOrderStorage _orderStorage;
|
||
|
||
public OrderLogic(IOrderStorage orderStorage)
|
||
{
|
||
_orderStorage = orderStorage;
|
||
}
|
||
|
||
public bool Create(OrderBindingModel model)
|
||
{
|
||
CheckModel(model, false);
|
||
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 OrderViewModel? ReadElement(OrderSearchModel model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return null;
|
||
}
|
||
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 Update(OrderBindingModel model)
|
||
{
|
||
CheckModel(model, false);
|
||
if (_orderStorage.Update(model) == null) { return false; }
|
||
return true;
|
||
}
|
||
|
||
private void CheckModel(OrderBindingModel model, bool param = true)
|
||
{
|
||
if (model == null)
|
||
{
|
||
throw new ArgumentNullException($"Объект \"{model}\" нулл");
|
||
}
|
||
if (!param)
|
||
{
|
||
return;
|
||
}
|
||
if (model.FIO == null || string.IsNullOrEmpty(model.FIO))
|
||
{
|
||
throw new ArgumentNullException("Что-то с именем клиента - его нет почему-то");
|
||
}
|
||
if (model.OrderDestination == null || string.IsNullOrEmpty(model.OrderDestination))
|
||
{
|
||
throw new ArgumentNullException("что-то с путём заказа - его нет почему-то");
|
||
}
|
||
if (model.OrderDeliveryTime == null)
|
||
{
|
||
throw new ArgumentNullException("Что-то со сроком доставки, его почему-то нет");
|
||
}
|
||
}
|
||
}
|
||
}
|