public void LoginWithWhere(string username) { var allUsersWithagivenUsername = Users.Where(u => u.Username == username).ToList(); if (allUsersWithagivenUsername.Count == 0) { CurrentUser = null; } else if (allUsersWithagivenUsername.Count == 1) { CurrentUser = allUsersWithagivenUsername[0]; } else { throw new ApplicationException($"More than one user found with username {username}"); } }
public void Login(string username) { try { CurrentUser = Users.SingleOrDefault(u => u.Username == username); } catch (Exception ex) { Console.WriteLine("Log something"); // throw ex; // Don't do this!!! // Catch - and - release, continues the original exception // throw; // Creates a new exception that contains the original one, and adds information throw new ApplicationException($"More than one user found with username {username}", ex); } }
public void AddUser(IUserLike user) { Users.Add(user); user.Academy = this; }