Пример #1
0
        public Error Set(CmsCategoryEntity src)
        {
            if (src.ParentId != 0 && src.ParentId == this.value.ID)
            {
                return(new Error("父级栏目有误:与子栏目相同"));
            }

            if (this.value.ID <= 0)
            {
                if (src.SiteId <= 0)
                {
                    return(new Error("参数错误:SiteId"));
                }
                if (String.IsNullOrEmpty(src.Tag))
                {
                    return(new Error("缺少参数:Tag"));
                }
                if (String.IsNullOrEmpty(src.Name))
                {
                    return(new Error("栏目名称不能为空"));
                }
                this.value.SiteId = src.SiteId;
                this.value.Code   = src.Code ?? "";
                this.value.Tag    = src.Tag ?? "";
                this.value.Icon   = "";
                this.value.Path   = "";
                this.value.Flag   = 0; //todo: 初始化flag
                int maxSortNumber = this._repo.GetMaxSortNumber(this.value.SiteId);
                if (maxSortNumber == 0)
                {
                    maxSortNumber = 1;
                }
                this.value.SortNumber = maxSortNumber;
                this._pathChanged     = true;
            }
            if (src.Tag == "-")
            {
                return(new Error("不允许使用栏目保留Tag"));
            }
            if (src.ParentId == 0 && this.errTags.Contains(src.Tag))
            {
                return(new Error("不允许使用保留栏目Tag"));
            }

            if (this.value.ParentId != src.ParentId)
            {
                if (src.ParentId > 0)
                {
                    ICategory ip = this._repo.GetCategory(this.value.SiteId, src.ParentId);
                    if (ip == null || ip.Get().SiteId != this.value.SiteId)
                    {
                        return(new Error("上级分类不存在"));
                    }
                }
                this.value.ParentId = src.ParentId;
                this._pathChanged   = true;
            }
            if (String.IsNullOrEmpty(src.Tag))
            {
                return(new Error("栏目tag不能为空"));
            }
            if (!this._repo.CheckTagMatch(this.value.SiteId, this.value.ParentId, src.Tag, this.value.ID))
            {
                return(new Error("分类TAG已存在"));
            }
            if (this.value.Tag != src.Tag)
            {
                this._pathChanged = true;
            }
            this.value.Tag         = src.Tag;
            this.value.Flag        = src.Flag;
            this.value.ModuleId    = src.ModuleId;
            this.value.Name        = src.Name ?? "";
            this.value.Icon        = src.Icon ?? "";
            this.value.Title       = src.Title ?? "";
            this.value.Keywords    = src.Keywords ?? "";
            this.value.Description = src.Description ?? "";
            this.value.Location    = src.Location ?? "";
            if (String.IsNullOrEmpty(src.Location))
            {
                this.value.Flag ^= (int)CategoryFlag.Redirect;
            }
            else
            {
                this.value.Flag |= (int)CategoryFlag.Redirect;
            }
            return(null);
        }
Пример #2
0
        public Result SaveCategory(int siteId, int parentId, CategoryDto category)
        {
            ISite     site = this.repo.GetSiteById(siteId);
            ICategory ic   = null;

            if (category.ID > 0)
            {
                ic = site.GetCategory(category.ID);
            }
            if (ic == null)
            {
                ic = _categoryRep.CreateCategory(new CmsCategoryEntity());
            }
            CmsCategoryEntity cat = new CmsCategoryEntity();

            cat.SiteId      = siteId;
            cat.Keywords    = category.Keywords;
            cat.Description = category.Description;
            cat.ParentId    = parentId;
            cat.Tag         = category.Tag;
            cat.Icon        = category.Icon;
            cat.Name        = category.Name;
            cat.Title       = category.PageTitle;
            cat.SortNumber  = category.SortNumber;
            cat.ModuleId    = category.ModuleId;
            cat.Location    = category.Location;
            Error err = ic.Set(cat);

            if (err == null)
            {
                // 保存模板
                List <TemplateBind> binds = new List <TemplateBind>();
                if (!String.IsNullOrEmpty(category.CategoryTemplate))
                {
                    binds.Add(new TemplateBind(0, TemplateBindType.CategoryTemplate, category.CategoryTemplate));
                }
                if (!String.IsNullOrEmpty(category.CategoryArchiveTemplate))
                {
                    binds.Add(new TemplateBind(0, TemplateBindType.CategoryArchiveTemplate, category.CategoryArchiveTemplate));
                }
                err = ic.SetTemplates(binds.ToArray());
                if (err == null)
                {
                    // 扩展属性
                    if (category.ExtendFields != null)
                    {
                        ic.ExtendFields = category.ExtendFields;
                    }
                    if (err == null)
                    {
                        err = ic.Save();
                    }
                }
            }

            #region 扩展属性



            #endregion

            Result r = new Result();
            if (err == null)
            {
                r.Data = new Dictionary <String, String>();
                r.Data["CategoryId"] = ic.GetDomainId().ToString();
            }
            else
            {
                r.ErrCode = 1;
                r.ErrMsg  = err.Message;
            }
            return(r);
        }
Пример #3
0
 public ICategory CreateCategory(CmsCategoryEntity value)
 {
     return(base.CreateCategory(this, _siteRep, _extendRep, _tempRep, value));
 }