PIbd-22_Petrushin_E.A._LawFirm/LawFirm/LawFirmBusinessLogic/BusinessLogics/OrderLogic.cs
GokaPek 2af5c30a4f 2
2024-02-14 00:11:21 +04:00

60 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
}
}
}