コード例 #1
0
        public async Task DeleteGameSessionByAdmin(int gameSessionId, ClaimsPrincipal User)
        {
            GameSession gameSession = await _db.GameSessions.GetActiveGameSessionByIdAsync(gameSessionId);

            string userID = User.FindAll(ClaimTypes.NameIdentifier).FirstOrDefault().Value;

            string userAdminID = _db.Users.GetUserById(userID).Id;

            if (userAdminID != gameSession.UserAdminID)
            {
                var errorMessage = "You are not game session admin. U cant delete current game session";
                throw new RequestException(HttpStatusCode.BadRequest, errorMessage, LoggingEvents.DeleteGameSessionByAdmin);
            }
            await _db.RemoveGameSessionAsync(gameSession);

            var userProfile = await _db.Users.GetUserProfile(userID);

            await _db.UpdateNumberGamesSessionDeletedasAdmin(userProfile);
        }