From cb49d29e8d2ef6217e9e60e021ee6dc4a34ba043 Mon Sep 17 00:00:00 2001 From: ImNicolasTheDev Date: Sun, 7 May 2023 18:34:25 +0200 Subject: [PATCH] Transformed expressions (foreach) into a LINQ + fixed the addUser method so that it adds a user (not permanently) to the list of users in UserBase --- Sources/Console/Program.cs | 10 ++-------- Sources/Modèle/UserBase.cs | 14 ++++++++------ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/Sources/Console/Program.cs b/Sources/Console/Program.cs index 94fc1d0..daf546b 100644 --- a/Sources/Console/Program.cs +++ b/Sources/Console/Program.cs @@ -273,9 +273,6 @@ void menuMontres() return; } } while (choix != -1); // Tant que l'utilisateur n'appuie pas sur Echap - - - return; } //======================================= Fonctions d'affichage ============================================// @@ -344,12 +341,9 @@ void rechercheMonstre() { listCarac += carac.KeyChar; } - else if (carac.Key == ConsoleKey.Backspace) + else if (carac.Key == ConsoleKey.Backspace && !string.IsNullOrEmpty(listCarac)) { - if (!string.IsNullOrEmpty(listCarac)) - { - listCarac = listCarac.Remove(listCarac.Length - 1, 1); - } + listCarac = listCarac.Remove(listCarac.Length - 1, 1); } Console.Write(listCarac); diff --git a/Sources/Modèle/UserBase.cs b/Sources/Modèle/UserBase.cs index 6d25c64..143168b 100644 --- a/Sources/Modèle/UserBase.cs +++ b/Sources/Modèle/UserBase.cs @@ -57,13 +57,14 @@ namespace Model { return false; } - foreach (User u in ListUsers) + + foreach (var _ in from User u in ListUsers + where username.Equals(u.Pseudo) + select new { }) { - if (username.Equals(u.Pseudo)) - { - return true; - } + return true; } + return false; } @@ -74,7 +75,8 @@ namespace Model { return false; } - User user = new User(pseudo, nom, prenom, pssw); //POUR L'INSTANT -> Ne peux pas ajouter dans le stub + User user = new User(pseudo, nom, prenom, pssw); //POUR L'INSTANT, de manière non permanente + ListUsers.Add(user); return true; } }