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