public async Task <SingleGameSessionViewModel> JoinToCurrentGameSession(int gameSessionID, ClaimsPrincipal user) { string userID = user.FindAll(ClaimTypes.NameIdentifier).FirstOrDefault().Value; var currentUser = _db.Users.GetUserAndProfileById(userID); var currentGameSession = await _db.GameSessions.GetActiveGameSessionByIdAsync(gameSessionID); List <ApplicationUser> gameSessionPlayers = _db.GameSessionApplicationUsers.GetGameSessionPlayers(currentGameSession); var adminEvent = _db.Users.GetEventAdmin(currentGameSession); if (currentGameSession.SlotsFree == 0) { var errorMessage = "Slots full"; throw new RequestException(HttpStatusCode.BadRequest, errorMessage, LoggingEvents.JoinSingleGameSession); } else if (gameSessionPlayers.Contains(currentUser) || adminEvent == currentUser) { var errorMessage = "You are already in game"; throw new RequestException(HttpStatusCode.BadRequest, errorMessage, LoggingEvents.JoinSingleGameSession); } else { var gsAppUser = new GameSessionApplicationUser { ApplicationUserID = userID, GameSessionID = currentGameSession.ID, }; await _db.JoinGameSession(gsAppUser, currentGameSession); _logger.LogInformation(LoggingEvents.CreateNewGameSession, "Join to GameSession is successfully"); await _db.UpdateNumberGamesJoined(currentUser.Profile); var singleGameSessionAfterJoin = await GetSingleGameSessionAsync(currentGameSession.ID, user); return(singleGameSessionAfterJoin); } }