diff --git a/ConfectionaryFileImplement/ClientStorage.cs b/ConfectionaryFileImplement/ClientStorage.cs index 1de16fc..e082d8e 100644 --- a/ConfectionaryFileImplement/ClientStorage.cs +++ b/ConfectionaryFileImplement/ClientStorage.cs @@ -26,7 +26,16 @@ namespace ConfectioneryFileImplement public ClientViewModel? GetElement(ClientSearchModel model) { - return _source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.Id.HasValue) + return _source.Clients.FirstOrDefault(x => 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) diff --git a/ConfectionaryListImplement/ClientStorage.cs b/ConfectionaryListImplement/ClientStorage.cs index 77afa9a..9dcf91f 100644 --- a/ConfectionaryListImplement/ClientStorage.cs +++ b/ConfectionaryListImplement/ClientStorage.cs @@ -30,7 +30,16 @@ namespace ConfectioneryListImplement public ClientViewModel? GetElement(ClientSearchModel model) { - return _source.Clients.FirstOrDefault(x => x.Id == model.Id)?.GetViewModel; + if (model.Id.HasValue) + return _source.Clients.FirstOrDefault(x => 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) diff --git a/ConfectioneryContracts/SearchModels/ClientSearchModel.cs b/ConfectioneryContracts/SearchModels/ClientSearchModel.cs index f408cba..80da827 100644 --- a/ConfectioneryContracts/SearchModels/ClientSearchModel.cs +++ b/ConfectioneryContracts/SearchModels/ClientSearchModel.cs @@ -11,5 +11,7 @@ namespace ConfectioneryContracts.SearchModels public int? Id { get; set; } public string? Email { get; set; } + + public string? Password { get; set; } } } diff --git a/ConfectioneryDatabaseImplement/ClientStorage.cs b/ConfectioneryDatabaseImplement/ClientStorage.cs index 9e428b0..09e7a8b 100644 --- a/ConfectioneryDatabaseImplement/ClientStorage.cs +++ b/ConfectioneryDatabaseImplement/ClientStorage.cs @@ -23,7 +23,16 @@ namespace ConfectioneryDatabaseImplement.Implements public ClientViewModel? GetElement(ClientSearchModel model) { using var context = new ConfectioneryDatabase(); - return context.Clients.FirstOrDefault(x => 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)