From 1d8c53582b69306100f668d1154b131f8fa879d0 Mon Sep 17 00:00:00 2001 From: revengel66 Date: Fri, 21 Jun 2024 15:13:53 +0400 Subject: [PATCH] edit orderlogic --- .../BusinessLogic/OrderLogic.cs | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs index 277115d..c51b134 100644 --- a/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs +++ b/Pizzeria/PizzeriaBusinessLogic/BusinessLogic/OrderLogic.cs @@ -5,6 +5,7 @@ using PizzeriaContracts.SearchModels; using PizzeriaContracts.StorageContracts; using PizzeriaContracts.ViewModels; using PizzeriaDataModels.Enums; +using System.Xml.Linq; namespace PizzeriaBusinessLogic.BusinessLogic { @@ -13,13 +14,29 @@ namespace PizzeriaBusinessLogic.BusinessLogic private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; - + static readonly object _locker = new object(); public OrderLogic(ILogger logger, IOrderStorage orderStorage) { _logger = logger; _orderStorage = orderStorage; } - + public OrderViewModel? ReadElement(OrderSearchModel model) + { + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model.ClientId, model.Status, model.ImplementerId, model.DateFrom, model.DateTo, model.Id); + var element = _orderStorage.GetElement(model); + if (element == null) + { + _logger.LogWarning("ReadElement element not found"); + return null; + } + _logger.LogInformation("ReadElement find. Id:{Id}", element.Id); + return element; + } public bool CreateOrder(OrderBindingModel model) { @@ -42,7 +59,8 @@ namespace PizzeriaBusinessLogic.BusinessLogic public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList. OrderId: {Id}.", model?.Id); + _logger.LogInformation("ReadList. ClientId:{ClientId}.Status:{Status}.ImplementerId:{ImplementerId}.DateFrom:{DateFrom}.DateTo:{DateTo}OrderId:{Id}", + model?.ClientId, model?.Status, model?.ImplementerId, model?.DateFrom, model?.DateTo, model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) { @@ -92,6 +110,15 @@ namespace PizzeriaBusinessLogic.BusinessLogic } model.Status = status; + if (order.ImplementerId.HasValue) + { + model.ImplementerId = order.ImplementerId; + } + if (model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } + if (model.Status == OrderStatus.Готов) { model.DateImplement = DateTime.Now;