Example #1
0
        /// <summary>
        /// 添加默认网站。
        /// </summary>
        /// <param name="siteKey">唯一键。</param>
        /// <param name="siteName">网站名称。</param>
        /// <param name="shortName">网站简称。</param>
        /// <param name="description">描述。</param>
        /// <param name="domains">域名列表。</param>
        /// <returns>返回添加结果。</returns>
        public virtual async Task <bool> CreateDefaultSiteAsync(string siteKey, string siteName, string shortName, string description, IEnumerable <string> domains)
        {
            if (await _context.BeginTransactionAsync(async db =>
            {
                var site = new SiteAdapter
                {
                    SiteKey = siteKey,
                    SiteName = siteName,
                    ShortName = shortName ?? siteName,
                    Description = description
                };
                if (await db.As <SiteAdapter>().CreateAsync(site))
                {
                    foreach (var domain in domains)
                    {
                        var siteDomain = new SiteDomain
                        {
                            Domain = domain,
                            SiteId = site.Id
                        };
                        await db.CreateAsync(siteDomain);
                    }

                    return(true);
                }

                return(false);
            }))
            {
                Refresh();
                return(true);
            }

            return(false);
        }
Example #2
0
        /// <summary>
        /// 添加网站域名。
        /// </summary>
        /// <param name="domain">域名地址。</param>
        /// <returns>返回添加结果。</returns>
        public virtual DataResult CreateDomain(SiteDomain domain)
        {
            var sites = GetCacheDomains();

            if (sites.TryGetValue(domain.Domain, out _))
            {
                return(DataAction.Duplicate);
            }
            return(FromResult(_context.Create(domain), DataAction.Created));
        }
Example #3
0
        /// <summary>
        /// 添加网站域名。
        /// </summary>
        /// <param name="domain">域名地址。</param>
        /// <returns>返回添加结果。</returns>
        public virtual async Task <DataResult> CreateDomainAsync(SiteDomain domain)
        {
            var sites = await GetCacheDomainsAsync();

            if (sites.TryGetValue(domain.Domain, out _))
            {
                return(DataAction.Duplicate);
            }
            return(FromResult(await _context.CreateAsync(domain), DataAction.Created));
        }