From 0a16389cb0ac7cfc0ec922a8254abd2b807c7d9a Mon Sep 17 00:00:00 2001 From: DyCTaTOR <125912249+DyCTaTOR@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:37:08 +0400 Subject: [PATCH] -- --- .../BusinessLogics/OrderLogic.cs | 68 ++++++++++++++----- 1 file changed, 50 insertions(+), 18 deletions(-) diff --git a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs index 674bc70..28467f3 100644 --- a/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/PlumbingRepair/PlumbingRepairBusinessLogic/BusinessLogics/OrderLogic.cs @@ -4,6 +4,7 @@ using PlumbingRepairContracts.BusinessLogicsContracts; using PlumbingRepairContracts.SearchModels; using PlumbingRepairContracts.StoragesContracts; using PlumbingRepairContracts.ViewModels; +using PlumbingRepairDataModels.Enums; using System; using System.Collections.Generic; using System.Linq; @@ -24,7 +25,7 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics } public List? ReadList(OrderSearchModel? model) { - _logger.LogInformation("ReadList.Id:{Id} ", model?.Id); + _logger.LogInformation("ReadList.OrderId:{Id} ", model?.Id); var list = model == null ? _orderStorage.GetFullList() : _orderStorage.GetFilteredList(model); if (list == null) @@ -54,34 +55,59 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics public bool CreateOrder(OrderBindingModel model) { CheckModel(model); + if (model.Status != OrderStatus.Неизвестен) + { + _logger.LogWarning("Insert operation failed. Order Status incorrect."); + return false; + } + + model.Status = OrderStatus.Принят; + if (_orderStorage.Insert(model) == null) { + model.Status = OrderStatus.Неизвестен; _logger.LogWarning("Insert operation failed"); return false; } + return true; } - public bool Update(OrderBindingModel model) + public bool StatusUpdate(OrderBindingModel model) { CheckModel(model); + if(model.Status + 1 > OrderStatus.Выдан) + { + _logger.LogWarning("Status update: operation failed. Order status incorrect."); + return false; + } + model.Status += 1; + if(model.Status == OrderStatus.Выдан) + { + model.DateImplement = DateTime.Now; + } if (_orderStorage.Update(model) == null) { + model.Status--; _logger.LogWarning("Update operation failed"); return false; } return true; } - public bool Delete(OrderBindingModel model) + public bool TakeOrderInWork(OrderBindingModel model) { - CheckModel(model, false); - _logger.LogInformation("Delete. Id:{Id}", model.Id); - if (_orderStorage.Delete(model) == null) - { - _logger.LogWarning("Delete operation failed"); - return false; - } - return true; + return StatusUpdate(model); } + + public bool DeliveryOrder(OrderBindingModel model) + { + return StatusUpdate(model); + } + + public bool FinishOrder(OrderBindingModel model) + { + return StatusUpdate(model); + } + private void CheckModel(OrderBindingModel model, bool withParams = true) { if (model == null) @@ -92,15 +118,21 @@ namespace PlumbingRepairBusinessLogic.BusinessLogics { return; } - _logger.LogInformation("Component.Id: {Id}", model.Id); - var element = _orderStorage.GetElement(new OrderSearchModel + if (model.WorkId < 0) { - WorkName = model.WorkName - }); - if (element != null && element.Id != model.Id) - { - throw new InvalidOperationException("Работа с таким названием уже есть"); + throw new ArgumentNullException("Некорректный идентификатор изделия", nameof(model.WorkId)); } + + if (model.Count <= 0) + { + throw new ArgumentNullException("Количество изделий в заказе должно быть больше 0", nameof(model.Count)); + } + + if (model.Sum <= 0) + { + throw new ArgumentNullException("Сумма заказа должна быть больше 0", nameof(model.Sum)); + } + _logger.LogInformation("Order. OrderId:{Id}.Sum:{ Sum}. WorkId: { WorkId}", model.Id, model.Sum, model.WorkId); } } }