Пример #1
0
        /// <summary>
        ///     站点发布
        /// </summary>
        /// <param name="themePublish"></param>
        /// <returns></returns>
        public ServiceResult Publish(ThemePublish themePublish)
        {
            if (themePublish.Theme == null)
            {
                return(ServiceResult.FailedWithMessage("模板不能为空"));
            }

            //if (!themePublish.Tenant.Equals(HttpWeb.Tenant, StringComparison.CurrentCultureIgnoreCase)) {
            //    return ServiceResult.FailedWithMessage("租户设置错误");
            //}

            // 模板不存在则添加模板
            var theme = Resolve <IThemeService>().GetSingle(r => r.Id == themePublish.Theme.Id);

            if (theme == null)
            {
                // 和服务器ID模板一样
                theme    = new Theme();
                theme.Id = themePublish.Theme.Id;
                Resolve <IThemeService>().Add(theme);
            }

            theme            = themePublish.Theme;
            theme.UpdateTime = DateTime.Now;
            if (!Resolve <IThemeService>().Update(theme))
            {
                return(ServiceResult.FailedWithMessage("模板更新失败"));
            }

            //修改默认模板
            Resolve <IThemeService>().SetDefaultTheme(theme.Id);

            var addList = new List <ThemePage>();

            foreach (var themePage in themePublish.PageList)
            {
                addList.Add(themePage);
            }

            if (addList.Count > 0)
            {
                Resolve <IThemePageService>().DeleteMany(r => r.ThemeId == themePublish.Theme.Id);
                Resolve <IThemePageService>().AddMany(addList);
            }

            // 清除缓存
            var cacheKey = $"AllThemePageInfo_{themePublish.Theme.ClientType.ToString()}";

            ObjectCache.Remove(cacheKey);
            cacheKey = $"AllThemePageInfo_{theme.Type.ToStr()}_{theme.ClientType.ToStr()}";
            ObjectCache.Remove(cacheKey);
            cacheKey = $"AllThemePageInfo_{themePublish.Theme.Id.ToString()}";
            ObjectCache.Remove(cacheKey);

            return(ServiceResult.Success);
        }
Пример #2
0
        public ApiResult PublishAsync([FromBody] ThemePublish parameter)
        {
            var tenant = HttpWeb.Tenant;

            if (!this.IsFormValid())
            {
                return(ApiResult.Failure(this.FormInvalidReason()));
            }

            var result = Resolve <IThemeOpenService>().Publish(parameter);

            return(ToResult(result));
        }