diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs index aeba2c9..74ea89c 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/BusinessLogics/OrderLogic.cs @@ -2,6 +2,7 @@ using JewelryStoreContracts.BusinessLogicsContracts; using JewelryStoreContracts.SearchModels; using JewelryStoreContracts.StoragesContracts; +using JewelryStoreContracts.StoragesModels; using JewelryStoreContracts.ViewModels; using JewelryStoreDataModels.Enums; using Microsoft.Extensions.Logging; @@ -12,12 +13,14 @@ namespace JewelryStoreBusinessLogic.BusinessLogics { private readonly ILogger _logger; private readonly IOrderStorage _orderStorage; + private readonly IStoreStorage _shopStorage; - public OrderLogic(ILogger logger, IOrderStorage orderStorage) + public OrderLogic(ILogger logger, IOrderStorage orderStorage, IStoreStorage shopStorage) { _logger = logger; _orderStorage = orderStorage; - } + _shopStorage = shopStorage; + } public bool CreateOrder(OrderBindingModel model) { @@ -34,22 +37,24 @@ namespace JewelryStoreBusinessLogic.BusinessLogics public bool DeliveryOrder(OrderBindingModel model) { - CheckModel(model, false); - var element = _orderStorage.GetElement(new OrderSearchModel - { - Id = model.Id - }); - if (element == null) - { - _logger.LogWarning("Read operation failed"); - return false; - } - if (element.Status != OrderStatus.Готов) - { - _logger.LogWarning("Status change operation failed"); - throw new InvalidOperationException("Заказ должен быть переведен в статус готовности перед выдачей!"); - } - model.Status = OrderStatus.Выдан; + var order = _orderStorage.GetElement(new OrderSearchModel + { + Id = model.Id, + }); + if (order == null) + { + throw new ArgumentNullException(nameof(order)); + } + if (!_shopStorage.RestockingShops(new SupplyBindingModel + { + JewelId = order.JewelId, + Count = order.Count + })) + { + throw new ArgumentException("Недостаточно места"); + } + + model.Status = OrderStatus.Выдан; model.DateImplement = DateTime.Now; _orderStorage.Update(model); return true; diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs index ad783a9..0f3eccd 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/ExcelInfo.cs @@ -7,8 +7,8 @@ using System.Threading.Tasks; namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels { - public class ExcelInfo - { + public class ExcelInfo : IDocument + { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List JewelComponents diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs index 0b7cf2b..dc142c2 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/PdfInfo.cs @@ -7,8 +7,8 @@ using System.Threading.Tasks; namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels { - public class PdfInfo - { + public class PdfInfo : IDocument + { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public DateTime DateFrom { get; set; } diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordInfo.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordInfo.cs index e09243c..5831756 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordInfo.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/HelperModels/WordInfo.cs @@ -7,8 +7,8 @@ using System.Threading.Tasks; namespace JewelryStoreBusinessLogic.OfficePackage.HelperModels { - public class WordInfo - { + public class WordInfo : IDocument + { public string FileName { get; set; } = string.Empty; public string Title { get; set; } = string.Empty; public List Jewels { get; set; } = new(); diff --git a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToExcel.cs b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToExcel.cs index c503792..6f6a4f8 100644 --- a/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToExcel.cs +++ b/PIbd-23_Panina.A.D_JewelryStore/JewelryStoreBusinessLogic/OfficePackage/Implements/SaveToExcel.cs @@ -195,7 +195,7 @@ namespace JewelryStoreBusinessLogic.OfficePackage.Implements _ => 0U, }; } - protected override void CreateExcel(ExcelInfo info) + protected override void CreateExcel(IDocument info) { _spreadsheetDocument = SpreadsheetDocument.Create(info.FileName, SpreadsheetDocumentType.Workbook); @@ -327,7 +327,7 @@ namespace JewelryStoreBusinessLogic.OfficePackage.Implements }; mergeCells.Append(mergeCell); } - protected override void SaveExcel(ExcelInfo info) + protected override void SaveExcel(IDocument info) { if (_spreadsheetDocument == null) {