2023-05-02 22:51:41 +04:00
|
|
|
|
using RestaurantContracts.BindingModels;
|
|
|
|
|
using RestaurantContracts.BusinessLogicsContracts;
|
|
|
|
|
using RestaurantContracts.SearchModels;
|
|
|
|
|
using RestaurantContracts.StoragesContracts;
|
|
|
|
|
using RestaurantContracts.ViewModels;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
namespace RestaurantBusinessLogic.BusinessLogics
|
|
|
|
|
{
|
|
|
|
|
public class OrderLogic : IOrderLogic
|
|
|
|
|
{
|
|
|
|
|
private readonly IOrderStorage _orderStorage;
|
|
|
|
|
|
|
|
|
|
public OrderLogic(IOrderStorage orderStorage)
|
|
|
|
|
{
|
|
|
|
|
_orderStorage = orderStorage;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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 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 Update(OrderBindingModel model)
|
|
|
|
|
{
|
|
|
|
|
CheckModel(model);
|
|
|
|
|
if (_orderStorage.Update(model) == null)
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CheckModel(OrderBindingModel model, bool withParams = true)
|
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException(nameof(model));
|
|
|
|
|
}
|
|
|
|
|
if (!withParams)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (model.Price <= 0)
|
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Нет цены у заказа", nameof(model.Price));
|
|
|
|
|
}
|
2023-05-16 23:26:45 +04:00
|
|
|
|
if (model.Date == null)
|
2023-05-02 22:51:41 +04:00
|
|
|
|
{
|
|
|
|
|
throw new ArgumentNullException("Нет даты у заказа", nameof(model.Date));
|
|
|
|
|
}
|
|
|
|
|
var element = _orderStorage.GetElement(new OrderSearchModel
|
|
|
|
|
{
|
2023-05-08 13:51:25 +04:00
|
|
|
|
ClientId = model.ClientId,
|
2023-05-02 22:51:41 +04:00
|
|
|
|
Date = model.Date,
|
|
|
|
|
});
|
|
|
|
|
if (element != null && element.Id != model.Id)
|
|
|
|
|
{
|
|
|
|
|
throw new InvalidOperationException("Заказ с таким номером уже есть");
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-05-17 00:48:03 +04:00
|
|
|
|
|
|
|
|
|
public bool ClearList()
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.ClearList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string DiffGetTest(int count)
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.DiffGetTest(count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string GetTest(int count)
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.GetTest(count);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string SetTest(int count)
|
|
|
|
|
{
|
|
|
|
|
return _orderStorage.SetTest(count);
|
|
|
|
|
}
|
2023-05-02 22:51:41 +04:00
|
|
|
|
}
|
|
|
|
|
}
|