From 163e5f614ba944f5f443248f1317d968a0b22e0d Mon Sep 17 00:00:00 2001 From: "ityurner02@mail.ru" Date: Mon, 17 Apr 2023 18:18:07 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B2=D0=BE=D1=82=20=D1=82=D0=B5=D0=BF=D0=B5?= =?UTF-8?q?=D1=80=D1=8C=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ImplementerStorage.cs | 27 ++++++++----------- .../Implements/OrderStorage.cs | 7 +++-- 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs index fc0f124..744e8b8 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/ImplementerStorage.cs @@ -26,23 +26,18 @@ namespace PlumbingRepairDatabaseImplement.Implements public ImplementerViewModel? GetElement(ImplementerSearchModel model) { + if (string.IsNullOrEmpty(model.ImplementerFIO) && + string.IsNullOrEmpty(model.Password) && + !model.Id.HasValue) + { + return null; + } using var context = new PlumbingRepairDataBase(); - if (model.Id.HasValue) - { - return context.Implementers - .FirstOrDefault(x => (x.Id == model.Id))?.GetViewModel; - } - else if (!string.IsNullOrEmpty(model.ImplementerFIO) && !string.IsNullOrEmpty(model.Password)) - { - return context.Implementers - .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO && x.Password == model.Password))?.GetViewModel; - } - else if (!string.IsNullOrEmpty(model.ImplementerFIO)) - { - return context.Implementers - .FirstOrDefault(x => (x.ImplementerFIO == model.ImplementerFIO))?.GetViewModel; - } - return new(); + return context.Implementers + .FirstOrDefault(x => (string.IsNullOrEmpty(model.ImplementerFIO) || x.ImplementerFIO == model.ImplementerFIO) && + (string.IsNullOrEmpty(model.Password) || x.Password == model.Password) && + (!model.Id.HasValue || x.Id == model.Id)) + ?.GetViewModel; } public List GetFilteredList(ImplementerSearchModel model) diff --git a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs index 9cdca71..b320120 100644 --- a/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs +++ b/PlumbingRepair/PlumbingRepairDatabaseImplement/Implements/OrderStorage.cs @@ -86,10 +86,9 @@ namespace PlumbingRepairDatabaseImplement.Implements .Include(x => x.Work) .Include(x => x.Client) .Include(x => x.Implementer) - .FirstOrDefault(x => (model.Status == null || model.Status != null && model.Status == x.Status) && - model.ImplementerId.HasValue && x.ImplementerId == model.ImplementerId || - model.Id.HasValue && x.Id == model.Id) - ?.GetViewModel; + .FirstOrDefault(x => (!model.ImplementerId.HasValue || x.ImplementerId == model.ImplementerId) && + (!model.Status.HasValue || x.Status == model.Status) && + (!model.Id.HasValue || x.Id == model.Id))?.GetViewModel; } public OrderViewModel? Insert(OrderBindingModel model)