Beispiel #1
0
        public bool TryUpdateKey(IDbConnection connection, int systemId, string oldName, string newName,
                                 IGDetailSystemLocalStorageCache cache, bool updateParentCahce = true)
        {
            _checkAndInit(connection, cache);
            int id;

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

            user.Name = newName;
            var result = cache.UpdateLocalItem(connection, user);

            return(result.Name == newName);
        }
Beispiel #2
0
        public int GetOrAdd(IDbConnection connection, string systemName, IGDetailSystemLocalStorageCache cache)
        {
            var val = TryGetValue(connection, systemName, cache);

            if (val != 0)
            {
                return(val);
            }
            var cacheSystem = cache.LocalOperation(connection, col => col.FirstOrDefault(i => i.Name == systemName));

            if (cacheSystem != null && cacheSystem.Id != 0)
            {
                return(_storage.AddOrUpdateSimple(cacheSystem.Name, cacheSystem.Id));
            }
            var repo      = cache.GetRepository();
            var tableName = repo.SchemeTableName;
            var sql       = $"SELECT TOP(1) * FROM {tableName} WHERE name=@systemName";
            var system    = repo.Provider.Text <g_detail_system>(connection, sql, new { systemName }).Single();

            cache.UpdateLocalItem(connection, repo.ConvertToWorkModel(system));
            return(_storage.AddOrUpdateSimple(system.name, system.Id));
        }