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