PIbd-22_Petrushin_E.A._LawFirm/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs

60 lines
1.8 KiB
C#
Raw Normal View History

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