From 2d5dccd197e14937b7241dd8cc03b9e43eff4522 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 9 Apr 2023 10:15:25 +0400 Subject: [PATCH 1/2] =?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=B8=D0=B5=20=D0=BF=D0=BE=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=83=D1=87=D0=B5=D0=BD=D0=B8=D1=8E=20=D1=8D=D0=BB=D0=B5=D0=BC?= =?UTF-8?q?=D0=B5=D0=BD=D1=82=D0=B0=20(=D0=9A=D0=BB=D0=B8=D0=B5=D0=BD?= =?UTF-8?q?=D1=82=D0=B0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ClientStorage.cs | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs index 4b8cc2a..50b0681 100644 --- a/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyDatabaseImplement/Implements/ClientStorage.cs @@ -28,27 +28,37 @@ namespace FurnitureAssemblyDatabaseImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password)) { return null; } using var context = new FurnitureAssemblyDatabase(); - return context.Clients - .FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Email) && x.Email == model.Email) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + if (model.Id.HasValue) + { + return context.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + } + if (model.Email != null && model.Password != null) + { + return context.Clients + .FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) + ?.GetViewModel; + } + if (model.Email != null) + { + return context.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel; + } + return null; } public List GetFilteredList(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) || string.IsNullOrEmpty(model.Password)) + if (string.IsNullOrEmpty(model.Email)) { return new(); } using var context = new FurnitureAssemblyDatabase(); return context.Clients - .Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) + .Where(x => x.Email.Equals(model.Email)) .Select(x => x.GetViewModel) .ToList(); } From fecc5004bad70b447861834a7aad6a5118bf25e4 Mon Sep 17 00:00:00 2001 From: prodigygirl Date: Sun, 9 Apr 2023 10:27:39 +0400 Subject: [PATCH 2/2] =?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=B8=D0=B5=20=D0=B2=20=D0=B4=D1=80=D1=83=D0=B3?= =?UTF-8?q?=D0=B8=D1=85=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8F=D1=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Implements/ClientStorage.cs | 25 +++++++++++++------ .../Implements/ClientStorage.cs | 21 ++++++++++------ 2 files changed, 31 insertions(+), 15 deletions(-) diff --git a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ClientStorage.cs b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ClientStorage.cs index 38e041a..9a3a4be 100644 --- a/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ClientStorage.cs +++ b/FurnitureAssembly/FurnitureAssemFileImplement/Implements/ClientStorage.cs @@ -32,16 +32,25 @@ namespace FurnitureAssemFileImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) + if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue && string.IsNullOrEmpty(model.Password)) { return null; + } + if (model.Id.HasValue) + { + return source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; } - return source.Clients - .FirstOrDefault(x => - (!string.IsNullOrEmpty(model.Email) && x.Email == - model.Email) || - (model.Id.HasValue && x.Id == model.Id)) - ?.GetViewModel; + if (model.Email != null && model.Password != null) + { + return source.Clients + .FirstOrDefault(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) + ?.GetViewModel; + } + if (model.Email != null) + { + return source.Clients.FirstOrDefault(x => x.Email.Equals(model.Email))?.GetViewModel; + } + return null; } public List GetFilteredList(ClientSearchModel model) @@ -51,7 +60,7 @@ namespace FurnitureAssemFileImplement.Implements return new(); } return source.Clients - .Where(x => x.Email.Equals(model.Email) && x.Password.Equals(model.Password)) + .Where(x => x.Email.Equals(model.Email)) .Select(x => x.GetViewModel) .ToList(); } diff --git a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ClientStorage.cs b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ClientStorage.cs index a4b75c1..effbc7c 100644 --- a/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ClientStorage.cs +++ b/FurnitureAssembly/FurnitureAssemblyListImplement/Implements/ClientStorage.cs @@ -32,15 +32,22 @@ namespace FurnitureAssemblyListImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { - if (string.IsNullOrEmpty(model.Email) && !model.Id.HasValue) - { - return null; - } foreach (var client in _source.Clients) { - if ((!string.IsNullOrEmpty(model.Email) && client.Email == model.Email) - || (model.Id.HasValue && client.Id == model.Id)) + if (model.Id.HasValue && client.Id == model.Id) + { + return client.GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Email) && !string.IsNullOrEmpty(model.Password) + && client.Email.Equals(model.Email) && client.Password.Equals(model.Password)) + { + return client.GetViewModel; + } + + if (!string.IsNullOrEmpty(model.Email) + && client.Email.Equals(model.Email)) { return client.GetViewModel; } @@ -57,7 +64,7 @@ namespace FurnitureAssemblyListImplement.Implements } foreach (var client in _source.Clients) { - if (client.Email.Equals(model.Email) && client.Password.Equals(model.Password)) + if (client.Email.Equals(model.Email)) { result.Add(client.GetViewModel); }