Ejemplo n.º 1
0
        public int SaveCategory(int siteId, int parentLft, CategoryDto category)
        {
            ISite     site = this._resp.GetSiteById(siteId);
            ICategory ic   = site.GetCategoryByLft(category.Lft);

            if (ic == null)
            {
                ic = _categoryRep.CreateCategory(-1, site);
            }
            //ic.CloneData(category);
            ic.Id          = category.Id;
            ic.Keywords    = category.Keywords;
            ic.Description = category.Description;
            ic.Tag         = category.Tag;
            ic.Icon        = category.Icon;
            ic.Name        = category.Name;
            ic.PageTitle   = category.PageTitle;
            ic.OrderIndex  = category.OrderIndex;
            ic.ModuleId    = category.ModuleId;
            ic.Location    = category.Location;

            bool isExistCategoryBind = false;
            bool isExistArchiveBind  = false;

            #region 模板绑定

            foreach (ITemplateBind tempBind in ic.Templates)
            {
                if (tempBind.BindType == TemplateBindType.CategoryTemplate)
                {
                    isExistCategoryBind = true;
                    tempBind.TplPath    = category.CategoryTemplate;
                }
                else if (tempBind.BindType == TemplateBindType.CategoryArchiveTemplate)
                {
                    isExistArchiveBind = true;
                    tempBind.TplPath   = category.CategoryArchiveTemplate;
                }
            }

            //栏目模板
            if (!isExistCategoryBind && !String.IsNullOrEmpty(category.CategoryTemplate))
            {
                ITemplateBind bind = this._tempRep.CreateTemplateBind(-1,
                                                                      TemplateBindType.CategoryTemplate,
                                                                      category.CategoryTemplate);

                bind.BindRefrenceId = ic.Id;
                ic.Templates.Add(bind);
            }

            //栏目文档模板
            if (!isExistArchiveBind && !String.IsNullOrEmpty(category.CategoryArchiveTemplate))
            {
                ITemplateBind bind = this._tempRep.CreateTemplateBind(-1,
                                                                      TemplateBindType.CategoryArchiveTemplate,
                                                                      category.CategoryArchiveTemplate);

                bind.BindRefrenceId = ic.Id;

                ic.Templates.Add(bind);
            }
            #endregion

            #region 扩展属性

            if (category.ExtendFields != null)
            {
                ic.ExtendFields = category.ExtendFields;
            }

            #endregion

            if (parentLft >= 0)
            {
                ic.Parent = site.GetCategoryByLft(parentLft);
            }
            return(ic.Save());
        }
Ejemplo n.º 2
0
        public CategoryDto GetCategoryByLft(int siteId, int lft)
        {
            ISite site = this._resp.GetSiteById(siteId);

            return(CategoryDto.ConvertFrom(site.GetCategoryByLft(lft)));
        }