/// <summary> /// 添加域名。 /// </summary> /// <param name="domain">网站域名。</param> /// <returns>返回添加结果。</returns> public virtual DataResult Create(SiteDomain domain) { if (LoadCacheDomains().ContainsKey(domain.Domain)) { return(DataAction.Duplicate); } if (_sddb.Create(domain)) { _cache.Remove(_cacheKey); return(DataAction.Created); } return(DataAction.CreatedFailured); }
/// <summary> /// 添加域名。 /// </summary> /// <param name="domain">网站域名。</param> /// <returns>返回添加结果。</returns> public virtual async Task <DataResult> CreateAsync(SiteDomain domain) { var domains = await LoadCacheDomainsAsync(); if (domains.ContainsKey(domain.Domain)) { return(DataAction.Duplicate); } if (await _sddb.CreateAsync(domain)) { _cache.Remove(_cacheKey); return(DataAction.Created); } return(DataAction.CreatedFailured); }
/// <summary> /// 初始化整个站的方法。 /// </summary> /// <typeparam name="TSite">网站类型。</typeparam> /// <param name="executor">数据库事务操作执行方法。</param> /// <param name="site">网站实例。</param> /// <param name="domain">域名实例。</param> /// <returns>返回安装结果。</returns> public virtual async Task <bool> InstallAsync <TSite>(Func <IDbTransactionContext <SiteDomain>, Task <bool> > executor, TSite site, SiteDomain domain) where TSite : SiteBase { if (domain.SiteId == 0) { domain.SiteId = site.SiteId; } domain.IsDefault = true; if (await _sddb.BeginTransactionAsync(async db => { if (!await executor(db)) { return(false); } if (!await db.As <TSite>().UpdateAsync(x => x.SiteId == site.SiteId, new { site.IsInitialized, site.SiteName, UpdatedDate = DateTimeOffset.Now, SettingValue = JsonConvert.SerializeObject(site) })) { return(false); } return(await db.As <SiteDomain>().CreateAsync(domain)); })) { InstallerHostedService.Current = InstallerStatus.Success; _cache.Remove(_cacheKey); return(true); } return(false); }