Example #1
0
        public int GetOrAdd(IDbConnection connection, string authId, IUserLocalStorageCache cache)
        {
            _checkAndInit(connection, cache);
            int val;

            _storage.TryGetValue(authId, out val);
            if (val != 0)
            {
                return(val);
            }
            var cacheUser = cache.LocalOperation(connection, col => col.FirstOrDefault(i => i.AuthId == authId));

            if (cacheUser != null && cacheUser.Id != 0)
            {
                return(_storage.AddOrUpdateSimple(cacheUser.AuthId, cacheUser.Id));
            }
            var repo      = cache.GetRepository();
            var tableName = repo.SchemeTableName;
            var sql       = $"SELECT TOP(1) * FROM {tableName} WHERE authId=@authId";
            var user      = repo.Provider.Text <user>(connection, sql, new { authId }).ToList();

            if (user.Any())
            {
                var u = user.First();
                cache.UpdateLocalItem(connection, repo.ConvertToWorkModel(u));
                return(_storage.AddOrUpdateSimple(u.authId, u.Id));
            }
            return(0);
        }
Example #2
0
        public UserDataModel AddOrUpdate(IDbConnection connection, UserDataModel dataModel)
        {
            var m = _userRepo.AddOrUpdateeModel(connection, dataModel);

            dataModel.Id = m.Id;
            var user = _userCache.UpdateLocalItem(connection, m);

            _userAuthToGameIdCache.AddOrUpdate(connection, user.AuthId, user.Id, _userCache);
            _userNameSercherPkCache.AddOrUpdate(connection, user.Nickname, user.Id, _userCache);
            return(user);
        }
Example #3
0
        public bool TryUpdateKey(IDbConnection connection, int userId, string oldUserName, string newUserName,
                                 IUserLocalStorageCache cache, bool updateParentCahce = true)
        {
            _checkAndInit(connection, cache);
            int id;

            if (!_storage.TryUpdateKey(oldUserName, newUserName, out id))
            {
                return(false);
            }
            if (!updateParentCahce)
            {
                return(true);
            }
            var user = cache.GetById(connection, id, true);

            user.Nickname = newUserName;
            var result = cache.UpdateLocalItem(connection, user);

            return(result.Nickname == newUserName);
        }
Example #4
0
        public int GetOrAdd(IDbConnection connection, string userName, IUserLocalStorageCache cache)
        {
            _checkAndInit(connection, cache);
            int val;

            _storage.TryGetValue(userName, out val);
            if (val != 0)
            {
                return(val);
            }
            var cacheUser = cache.LocalOperation(connection, col => col.FirstOrDefault(i => i.Nickname == userName));

            if (cacheUser != null && cacheUser.Id != 0)
            {
                return(_storage.AddOrUpdateSimple(cacheUser.Nickname, cacheUser.Id));
            }
            var repo      = cache.GetRepository();
            var tableName = repo.SchemeTableName;
            var sql       = $"SELECT TOP(1) * FROM {tableName} WHERE nickname=@userName";
            var user      = repo.Provider.Text <user>(connection, sql, new { userName }).Single();

            cache.UpdateLocalItem(connection, repo.ConvertToWorkModel(user));
            return(_storage.AddOrUpdateSimple(user.authId, user.Id));
        }