public void UpdateAllUsersRating(IDbConnection connection)
        {
            var users = _gameUserService.GetGameUserList(connection, false);

            foreach (var user in users)
            {
                user.PvpPoint = Rand.Next(0, 10000);
                _gameUserService.AddOrUpdate(connection, user);
            }
        }
        public UserDataModel CreateGameUser(IDbConnection connection, string userAuthId, string userName, ref bool existBefore, int?userId = null)
        {
            var user = _gameUserService.GetGameUser(connection, userAuthId);

            if (user != null && user.Id != 0)
            {
                existBefore = true;
                return(user);
            }
            var newUser = _gameUserService.AddOrUpdate(connection, _createUserModel(userAuthId, userName));

            if (userId != null)
            {
                newUser.Id = (int)userId;
            }
            return(newUser);
        }
        private void CreateNpc(IDbConnection connection, NpcModel npc)
        {
            // _dbProvider.Exec(connection, sqlResetIdentity);
            var npcKey = npc.NpcUser.Id;
            // npc.NpcUser.Id = 0;
            var insertedUser = _gameUserService.AddOrUpdate(connection, npc.NpcUser);

            if (insertedUser.Id != npcKey && npcKey != 0)
            {
                throw new NotImplementedException("insertedUser.Id!= npcKey");
            }
            npc.NpcUser.Id = insertedUser.Id;


            var npcAlliance = _allianceService.AddOrUpdate(connection, npc.NpcAlliance);

            if (npcAlliance.Id != npcKey)
            {
                throw new NotImplementedException("npcAlliance.Id != npcKey");
            }
            npc.NpcAlliance.Id = npcKey;

            var npcAllianceUser = _allianceService.GetAllianceUserById(connection, npcKey);

            if (npcAllianceUser == null)
            {
                throw new NotImplementedException("creator alliance user incorrect");
            }

            var password   = Guid.NewGuid().ToString();
            var npcChannel = _channelService.CreateAllianceChannel(connection, npcAlliance, password);

            if (npc.NpcUser.Id == Npc.ConfederationGameUserId)
            {
                _channelService.CreateMessage(connection, new ChannelMessageDataModel
                {
                    UserId     = npc.NpcUser.Id,
                    DateCreate = UnixTime.UtcNow(),
                    ChannelId  = npcChannel.Id,
                    UserName   = npc.NpcUser.Nickname,
                    Message    = "Welcome to Confederation!",
                    UserIcon   = npc.NpcUser.Avatar.Icon
                });
            }
        }