private bool UserAlreadyExists(User newUser, Users users) { return users .Items .Any( user => user.UserName.Equals( newUser.UserName, StringComparison.OrdinalIgnoreCase ) ); }
public bool TrySave(User newUser) { lock (locker) { using (var session = this.database.OpenSession()) { var users = session.Load<Users>("users") ?? new Users(); if (UserAlreadyExists(newUser, users)) { return false; } users.Items.Add(newUser); session.SaveChanges(); } } return true; }