From f9e191a08fa7cb3ec9bdd79e9a8ab236b28909dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=9C=D0=B0=D0=BB?= =?UTF-8?q?=D0=B0=D1=84=D0=B5=D0=B5=D0=B2?= Date: Tue, 28 May 2024 10:37:29 +0400 Subject: [PATCH] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/StorekeeperStorage.cs | 21 ++++++++------- .../Implements/WorkerStorage.cs | 27 ++++++++++--------- 2 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/StorekeeperStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/StorekeeperStorage.cs index 829a214..93092ff 100644 --- a/CarCenter/CarCenterDatabaseImplement/Implements/StorekeeperStorage.cs +++ b/CarCenter/CarCenterDatabaseImplement/Implements/StorekeeperStorage.cs @@ -24,25 +24,26 @@ namespace CarCenterDatabaseImplement.Implements } public List GetFilteredList(StorekeeperSearchModel model) { - if (model == null) + if (!model.Id.HasValue) { return new(); } - - if (model.Id.HasValue) + using var context = new CarCenterDatabase(); + if (model.Id.HasValue) { - var res = GetElement(model); - - return res != null ? new() { res } : new(); - } - return new(); + return context.Storekeepers.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + else + { + return new(); + } } public StorekeeperViewModel? GetElement(StorekeeperSearchModel model) { using var context = new CarCenterDatabase(); - - if (model.Id.HasValue) + if (!model.Id.HasValue) { return null; } + if (model.Id.HasValue) return context.Storekeepers .FirstOrDefault(x => x.Id == model.Id) ?.GetViewModel; diff --git a/CarCenter/CarCenterDatabaseImplement/Implements/WorkerStorage.cs b/CarCenter/CarCenterDatabaseImplement/Implements/WorkerStorage.cs index 047618b..442e698 100644 --- a/CarCenter/CarCenterDatabaseImplement/Implements/WorkerStorage.cs +++ b/CarCenter/CarCenterDatabaseImplement/Implements/WorkerStorage.cs @@ -24,19 +24,20 @@ namespace CarCenterDatabaseImplement.Implements } public List GetFilteredList(WorkerSearchModel model) { - if (model == null) - { - return new(); - } - - if (model.Id.HasValue) - { - var res = GetElement(model); - - return res != null ? new() { res } : new(); - } - return new(); - } + if (!model.Id.HasValue) + { + return new(); + } + using var context = new CarCenterDatabase(); + if (model.Id.HasValue) + { + return context.Workers.Where(x => x.Id == model.Id).Select(x => x.GetViewModel).ToList(); + } + else + { + return new(); + } + } public WorkerViewModel? GetElement(WorkerSearchModel model) {