public Player JoinGame(string userName) { switch (Status) { case GameStatus.Running: throw new BadRequestException("Cannot join game that has already started"); case GameStatus.Finished: throw new BadRequestException("Cannot join game that is finished"); } if (Players.Length >= MaxPlayers) { throw new BadRequestException("Max number of players"); } if (string.IsNullOrWhiteSpace(userName)) { throw new BadRequestException("Username cannot be empty"); } if (Players.Any(pl => userName.Equals(pl.UserName, StringComparison.InvariantCultureIgnoreCase))) { throw new BadRequestException("User with same name already registered"); } var player = new Player(userName); Players = Players.Append(player).ToArray(); return(player); }