Exemplo n.º 1
0
        /// <summary>
        /// 添加商户模板
        /// </summary>
        /// <param name="template"></param>
        /// <param name="isDefault"></param>
        /// <param name="templateId"></param>
        /// <returns></returns>
        public bool AddTemplate(ViewSiteTemplate template, bool isDefault, int templateId)
        {
            if (template.SiteID == 0)
            {
                return(this.FaildMessage("商户ID错误"));
            }
            if (string.IsNullOrEmpty(template.Name))
            {
                return(this.FaildMessage("模板名称错误"));
            }

            Site site = this.GetSiteInfo(template.SiteID);

            if (site.GetTemplateID(template.Platform) == 0)
            {
                isDefault = true;
            }
            if (isDefault)
            {
                template.Domain = string.Empty;
            }

            template.ID = ViewAgent.Instance().CopySystemTemplate(template.SiteID, templateId);
            if (isDefault)
            {
                Expression <Func <Site, int> > field = template.Platform switch
                {
                    PlatformSource.PC => t => t.PCTemplate,
                    PlatformSource.H5 => t => t.H5Template,
                    PlatformSource.APP => t => t.APPTemplate,
                    _ => null
                };
                this.WriteDB.Update(field, template.ID, t => t.ID == site.ID);
                SiteCaching.Instance().RemoveSiteInfo(site.ID);
            }
            template.Update(this.WriteDB, t => t.Name, t => t.Domain);
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 保存商户模板
        /// </summary>
        /// <param name="template"></param>
        /// <param name="models"></param>
        /// <returns></returns>
        public bool SaveSiteTemplateInfo(ViewSiteTemplate template, int[] models)
        {
            if (string.IsNullOrEmpty(template.Name))
            {
                return(this.FaildMessage("请输入模板名称"));
            }
            if (!string.IsNullOrEmpty(template.Domain) && !isDomain(template.Domain))
            {
                return(this.FaildMessage("域名错误,请重新输入域名"));
            }

            bool isNew = template.ID == 0;

            using (DbExecutor db = NewExecutor(IsolationLevel.ReadUncommitted))
            {
                if (template.ID == 0)
                {
                    template.AddIdentity(db);
                }
                else
                {
                    template.Update(db, t => t.Name, t => t.Platform, t => t.Domain);
                }

                //# 得到当前平台下所有的视图
                List <ViewSetting> views     = db.ReadList <ViewSetting>(t => t.Platform == template.Platform);
                List <ViewModel>   modelList = new List <ViewModel>();
                foreach (int modelId in models)
                {
                    ViewModel model = db.ReadInfo <ViewModel>(t => t.ID == modelId);
                    if (model == null)
                    {
                        db.Rollback();
                        return(this.FaildMessage($"模型ID{modelId}不存在"));
                    }
                    ViewSiteConfig config = isNew ? null :
                                            config = db.ReadInfo <ViewSiteConfig>(t => t.TemplateID == template.ID && t.ViewID == model.ViewID && t.SiteID == template.SiteID);
                    if (config != null && config.ModelID != modelId)
                    {
                        config.ModelID = modelId;
                        config.Update(db, t => t.ModelID);
                    }
                    else if (config == null)
                    {
                        config = new ViewSiteConfig()
                        {
                            TemplateID = template.ID,
                            ViewID     = model.ViewID,
                            ModelID    = model.ID,
                            SiteID     = template.SiteID
                        };
                        config.Add(db);
                    }
                    modelList.Add(model);
                }

                ViewSetting view = views.FirstOrDefault(t => !modelList.Any(p => p.ViewID == t.ID));
                if (view != null)
                {
                    db.Rollback();
                    return(this.FaildMessage($"视图{view.Name}未选则模型"));
                }

                db.AddCallback(() =>
                {
                    SiteCaching.Instance().RemoveSiteInfo(template.SiteID);
                });

                db.Commit();
            }

            return(this.AccountInfo.Log(LogType.View, $"保存系统模板 {template.Platform}/{template.Name}"));
        }