private bool AddParticipantToTable(int tableId) { List <GameTable> gameTableList = GameRepository.Instance.Get(); GameTable gameTable = gameTableList?.Find(table => table.Identifier.Equals(tableId)); if (ParticipationService.IsAlreadyParticipating(gameTable, User.Identity.Name)) { return(true); } return(ParticipationService.AddParticipation(gameTable, User.Identity.Name)); }
public GameTable ConnectToTable(int gameTableId) { lock (Locker) { GameTable table = GameTableService.GetTable(Games, gameTableId); string curUser = Context.User.Identity.Name; List <HandCard> cards = null; if (GameTableService.AlreadyConnected(table, curUser)) { Participation participation = ParticipationService.GetParticipation(table, curUser); if (table.Participations.Count == GlobalDefinitions.NofParticipantsPerTable && !table.IsInitialized) { AllConnected(table); Clients.Client(Context.ConnectionId).createGameTable(table, table.Identifier); } else { cards = table.CardServiceData?.GetActualHandCards(participation.Participant, table); Task task = Clients.Client(Context.ConnectionId).backToGame(table, cards, table.Identifier); task.Wait(); } if (table.ActualParticipation == participation) { NotifyActualPlayer(participation.Participant, cards, table.Identifier); } } else { ParticipationService.AddParticipation(table, curUser); Clients.Client(Context.ConnectionId).createGameTable(table); } return(table); } }