Exemplo n.º 1
0
 /// <summary>
 /// 保存应用程序。
 /// </summary>
 /// <param name="application">当前应用程序。</param>
 /// <returns>返回数据库操作结果。</returns>
 public virtual DataResult Save(Application application)
 {
     if (_context.Any(
             x => x.Id != application.Id && x.Name == application.Name && x.UserId == application.UserId))
     {
         return(DataAction.Duplicate);
     }
     if (application.Id > 0)
     {
         return(DataResult.FromResult(_context.Update(application), DataAction.Updated));
     }
     return(DataResult.FromResult(_context.Create(application), DataAction.Created));
 }
Exemplo n.º 2
0
        /// <summary>
        /// 保存网站配置实例。
        /// </summary>
        /// <param name="key">配置唯一键。</param>
        /// <param name="settings">网站配置实例。</param>
        public bool SaveSettings(string key, string settings)
        {
            var cacheKey = GetCacheKey(key, out var siteId);
            var adapter  = new SettingsAdapter {
                SettingKey = key, SettingValue = settings, SiteId = siteId
            };

            if (_db.Any(x => x.SettingKey == key && x.SiteId == siteId))
            {
                if (_db.Update(adapter))
                {
                    _cache.Remove(cacheKey);
                    return(true);
                }
            }
            return(_db.Create(adapter));
        }
Exemplo n.º 3
0
        /// <summary>
        /// 更新管理员权限配置。
        /// </summary>
        public void RefreshOwners()
        {
            var role = _rdb.Find(x => x.NormalizedName == DefaultRole.Owner.NormalizedName);

            if (role == null)
            {
                return;
            }
            var permissions = LoadCachePermissions().Values;

            foreach (var permission in permissions)
            {
                if (_prdb.Any(x => x.PermissionId == permission.Id && x.RoleId == role.RoleId))
                {
                    continue;
                }
                _prdb.Create(new PermissionInRole {
                    PermissionId = permission.Id, RoleId = role.RoleId, Value = PermissionValue.Allow
                });
            }
            RemoveCache();
        }
Exemplo n.º 4
0
        /// <summary>
        /// 更新管理员权限配置。
        /// </summary>
        public void RefreshOwners()
        {
            var roleId = GetOwnerId();

            if (roleId == 0)
            {
                return;
            }

            var permissions = LoadCachePermissions().Values;

            foreach (var permission in permissions)
            {
                if (_prdb.Any(x => x.PermissionId == permission.Id && x.RoleId == roleId))
                {
                    continue;
                }

                _prdb.Create(new PermissionInRole {
                    PermissionId = permission.Id, RoleId = roleId, Value = PermissionValue.Allow
                });
            }
            RemoveCache();
        }
Exemplo n.º 5
0
 /// <summary>
 /// 判断当前名称是否为非法名称。
 /// </summary>
 /// <param name="name">名称。</param>
 /// <returns>返回判断结果。</returns>
 public bool IsDisallowed(string name)
 {
     return(_context.Any(x => x.Name == name));
 }
Exemplo n.º 6
0
 /// <summary>
 /// 判断是否已经存在,唯一键重复。
 /// </summary>
 /// <param name="site">当前网站实例。</param>
 /// <returns>返回判断结果。</returns>
 public virtual bool IsDuplicated(SiteBase site)
 {
     return(_sdb.Any(x => x.SiteId != site.SiteId && x.SiteKey == site.SiteKey));
 }