public async override Task <Common.GrpcLibrary.Single.Types.BoolData> IsExists(Common.GrpcLibrary.Single.Types.StringData request, ServerCallContext context) { var res = await queryContext.AnyAsync <GSUser>(u => u.Name == request.Data); return(new Common.GrpcLibrary.Single.Types.BoolData() { Data = res }); }
/// <summary> /// 更新验证码实例。 /// </summary> /// <param name="captcha">验证码实例。</param> /// <returns>返回保存结果。</returns> public virtual async Task <bool> SaveCaptchAsync(Captcha captcha) { if (await _context.AnyAsync(x => x.PhoneNumber == captcha.PhoneNumber && x.Type == captcha.Type)) { return(await _context.UpdateAsync(x => x.PhoneNumber == captcha.PhoneNumber && x.Type == captcha.Type, new { captcha.Code, captcha.CaptchaExpiredDate })); } return(await _context.CreateAsync(captcha)); }
/// <summary> /// 保存注册码。 /// </summary> /// <param name="registration">注册码实例。</param> /// <returns>返回保存结果。</returns> public async Task <bool> SaveRegistrationAsync(Registration registration) { var lisence = new Lisence { Registration = Cores.Encrypto(registration.ToJsonString()) }; if (await _context.AnyAsync()) { return(await _context.UpdateAsync(lisence)); } return(await _context.CreateAsync(lisence)); }
/// <summary> /// 保存应用程序。 /// </summary> /// <param name="application">当前应用程序。</param> /// <returns>返回数据库操作结果。</returns> public virtual async Task <DataResult> SaveAsync(Application application) { if (await _context.AnyAsync( x => x.Id != application.Id && x.Name == application.Name && x.UserId == application.UserId)) { return(DataAction.Duplicate); } if (application.Id > 0) { return(DataResult.FromResult(await _context.UpdateAsync(application), DataAction.Updated)); } return(DataResult.FromResult(await _context.CreateAsync(application), DataAction.Created)); }
/// <summary> /// 保存网站配置实例。 /// </summary> /// <param name="key">配置唯一键。</param> /// <param name="settings">网站配置实例。</param> public virtual async Task <bool> SaveSettingsAsync(string key, string settings) { var cacheKey = GetCacheKey(key, out var siteId); var adapter = new SettingsAdapter { SettingKey = key, SettingValue = settings, SiteId = siteId }; if (await _db.AnyAsync(x => x.SettingKey == key && x.SiteId == siteId)) { if (await _db.UpdateAsync(adapter)) { _cache.Remove(cacheKey); return(true); } } return(await _db.CreateAsync(adapter)); }
/// <summary> /// 更新管理员权限配置。 /// </summary> public async Task RefreshOwnersAsync() { var role = await _rdb.FindAsync(x => x.NormalizedName == DefaultRole.Owner.NormalizedName); if (role == null) { return; } var permissions = await LoadCachePermissionsAsync(); foreach (var permission in permissions.Values) { if (await _prdb.AnyAsync(x => x.PermissionId == permission.Id && x.RoleId == role.RoleId)) { continue; } await _prdb.CreateAsync(new PermissionInRole { PermissionId = permission.Id, RoleId = role.RoleId, Value = PermissionValue.Allow }); } RemoveCache(); }
/// <summary> /// 更新管理员权限配置。 /// </summary> public async Task RefreshOwnersAsync() { var roleId = await GetOwnerIdAsync(); if (roleId == 0) { return; } var permissions = await LoadCachePermissionsAsync(); foreach (var permission in permissions.Values) { if (await _prdb.AnyAsync(x => x.PermissionId == permission.Id && x.RoleId == roleId)) { continue; } await _prdb.CreateAsync(new PermissionInRole { PermissionId = permission.Id, RoleId = roleId, Value = PermissionValue.Allow }); } RemoveCache(); }
/// <summary> /// 判断当前名称是否为非法名称。 /// </summary> /// <param name="name">名称。</param> /// <returns>返回判断结果。</returns> public async Task <bool> IsDisallowedAsync(string name) { return(await _context.AnyAsync(x => x.Name == name)); }
/// <summary> /// 判断是否禁用。 /// </summary> /// <returns>返回判断结果。</returns> public Task <bool> IsDisabledAsync() { return(_context.AnyAsync()); }
/// <summary> /// 判断是否已经存在,唯一键重复。 /// </summary> /// <param name="site">当前网站实例。</param> /// <returns>返回判断结果。</returns> public virtual Task <bool> IsDuplicatedAsync(SiteBase site) { return(_sdb.AnyAsync(x => x.SiteId != site.SiteId && x.SiteKey == site.SiteKey)); }
/// <summary> /// 判断域名是否已经存在。 /// </summary> /// <returns>返回判断结果。</returns> public virtual Task <bool> AnyAsync() => _context.AnyAsync();