From 998e352d2dde03e2ea17fb6aef9a36820e7f6ac5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=BE=D0=BB=D0=B0=D0=B9?= Date: Mon, 3 Apr 2023 18:23:22 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=BD=D0=B0=20=D0=B1=D0=B8=D0=B7=D0=BD=D0=B5=D1=81?= =?UTF-8?q?=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B8=20?= =?UTF-8?q?=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D1=83=D0=BF=D0=BA=D0=B8.=20=D0=A2=D0=B0=D0=BA?= =?UTF-8?q?=D0=B6=D0=B5=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=20=D0=B5=D1=89=D1=91=20=D0=BE=D0=B4=D0=B8=D0=BD=20=D1=81=D0=BF?= =?UTF-8?q?=D0=BE=D1=81=D0=BE=D0=B1=20=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80?= =?UTF-8?q?=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B4=D0=BB=D1=8F=20=D0=BF=D0=BE?= =?UTF-8?q?=D0=BA=D1=83=D0=BF=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BusinessLogics/Worker/PurchaseLogic.cs | 26 +++++++++++++++++-- .../BusinessLogicsContracts/IPurchaseLogic.cs | 2 +- .../SearchModels/PurchaseSearchModel.cs | 2 ++ .../Implements/Worker/PurchaseStorage.cs | 14 ++++++++-- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs index 8563aac..1239d9b 100644 --- a/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs +++ b/HardwareShop/HardwareShopBusinessLogic/BusinessLogics/Worker/PurchaseLogic.cs @@ -30,9 +30,21 @@ namespace HardwareShopContracts.BusinessLogicsContracts return list; } - public CommentViewModel? ReadElement(CommentSearchModel model) + public PurchaseSearchModel? ReadElement(PurchaseSearchModel model) { - throw new NotImplementedException(); + if (model == null) + { + throw new ArgumentNullException(nameof(model)); + } + _logger.LogInformation("ReadElement. Id:{Id}", model.Id); + var element = _purchaseStorage.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 DeliveryPurchase(PurchaseBindingModel model) @@ -78,6 +90,11 @@ namespace HardwareShopContracts.BusinessLogicsContracts public bool Update(PurchaseBindingModel model) { + if (model.PurchaseStatus == PurchaseStatus.Выдан) + { + _logger.LogWarning("Update status operation failed"); + return false; + } CheckModel(model); if (_purchaseStorage.Update(model) == null) { @@ -89,6 +106,11 @@ namespace HardwareShopContracts.BusinessLogicsContracts public bool Delete(PurchaseBindingModel model) { + if (model.PurchaseStatus == PurchaseStatus.Выдан) + { + _logger.LogWarning("Delete status operation failed"); + return false; + } CheckModel(model, false); _logger.LogInformation("Delete. Id:{Id}", model.Id); if (_purchaseStorage.Delete(model) == null) diff --git a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs index 0882fad..ba98e60 100644 --- a/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs +++ b/HardwareShop/HardwareShopContracts/BusinessLogicsContracts/IPurchaseLogic.cs @@ -7,7 +7,7 @@ namespace HardwareShopContracts.BusinessLogicsContracts public interface IPurchaseLogic { List? ReadList(PurchaseSearchModel? model); - CommentViewModel? ReadElement(CommentSearchModel model); + PurchaseSearchModel? ReadElement(PurchaseSearchModel model); bool Create(PurchaseBindingModel model); bool Update(PurchaseBindingModel model); bool Delete(PurchaseBindingModel model); diff --git a/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs b/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs index 1a62d47..7f2e5f6 100644 --- a/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs +++ b/HardwareShop/HardwareShopContracts/SearchModels/PurchaseSearchModel.cs @@ -7,5 +7,7 @@ namespace HardwareShopContracts.SearchModels public int? Id { get; set; } public int? UserId { get; set; } + + public DateTime? DatePurchase { get; set; } } } diff --git a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs index 8013365..cee197b 100644 --- a/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs +++ b/HardwareShop/HardwareShopDatabaseImplement/Implements/Worker/PurchaseStorage.cs @@ -25,15 +25,25 @@ namespace HardwareShopDatabaseImplement.Implements.Worker public List GetFilteredList(PurchaseSearchModel model) { using var context = new HardwareShopDatabase(); - if (!model.UserId.HasValue) + if (!model.UserId.HasValue && !model.DatePurchase.HasValue) { return new(); } + if (model.UserId.HasValue) + { + return context.Purchases + .Include(x => x.Goods) + .ThenInclude(x => x.Good) + .Include(x => x.User) + .Where(x => x.UserId == model.UserId) + .Select(x => x.GetViewModel) + .ToList(); + } return context.Purchases .Include(x => x.Goods) .ThenInclude(x => x.Good) .Include(x => x.User) - .Where(x => x.UserId == model.UserId) + .Where(x => x.DatePurchase == model.DatePurchase) .Select(x => x.GetViewModel) .ToList(); }