60 lines
1.8 KiB
C#
60 lines
1.8 KiB
C#
using LawFirmContracts.BindingModels;
|
||
using LawFirmContracts.BusinessLogicsContracts;
|
||
using LawFirmContracts.SearchModels;
|
||
using LawFirmContracts.StoragesContracts;
|
||
using LawFirmContracts.ViewModels;
|
||
using LawFirmDataModels.Enums;
|
||
using Microsoft.Extensions.Logging;
|
||
|
||
namespace LawFirmBusinessLogic.BusinessLogics
|
||
{
|
||
public class OrderLogic : IOrderLogic
|
||
{
|
||
private readonly ILogger _logger;
|
||
|
||
private readonly IOrderStorage _orderStorage;
|
||
|
||
public OrderLogic(ILogger<OrderLogic> logger, IOrderStorage orderStorage)
|
||
{
|
||
_logger = logger;
|
||
_orderStorage = orderStorage;
|
||
}
|
||
public bool CreateOrder(OrderBindingModel model)
|
||
{
|
||
if (_orderStorage.Insert(model) == null)
|
||
{
|
||
_logger.LogWarning("Insert operation failed");
|
||
return false;
|
||
}
|
||
model.Status = OrderStatus.Неизвестен;
|
||
return true;
|
||
}
|
||
|
||
public bool DeliveryOrder(OrderBindingModel model)
|
||
{
|
||
_logger.LogInformation("Delivery. Id:{Id}", model.Id);
|
||
model.Status = OrderStatus.Готов;
|
||
return _orderStorage.Update(model) != null;
|
||
}
|
||
|
||
public bool FinishOrder(OrderBindingModel model)
|
||
{
|
||
model.Status = OrderStatus.Выдан;
|
||
return _orderStorage.Update(model) != null;
|
||
}
|
||
|
||
public bool TakeOrderInWork(OrderBindingModel model)
|
||
{
|
||
model.Status = OrderStatus.Выполняется;
|
||
return _orderStorage.Update(model) != null;
|
||
}
|
||
public List<OrderViewModel>? ReadList(OrderSearchModel? model)
|
||
{
|
||
if (model == null)
|
||
{
|
||
return _orderStorage.GetFullList();
|
||
}
|
||
return _orderStorage.GetFilteredList(model);
|
||
}
|
||
}
|
||
} |