예제 #1
0
        private Result CloneCategoryDetails(int toSiteId, ICategory fromCate, int toCateId, bool includeExtend,
                                            bool includeTemplateBind)
        {
            var dto = CategoryDto.ConvertFrom(fromCate);

            dto.ID = 0;

            // 包含扩展
            if (!includeExtend)
            {
                dto.ExtendFields = new IExtendField[0];
            }
            else
            {
                dto.ExtendFields = new List <IExtendField>(fromCate.ExtendFields.Count);
                foreach (var extendField in fromCate.ExtendFields)
                {
                    var toField = GetCloneNewExtendField(toSiteId, extendField);
                    dto.ExtendFields.Add(toField);
                }
            }

            // 不包含模版
            if (!includeTemplateBind)
            {
                dto.CategoryTemplate        = null;
                dto.CategoryArchiveTemplate = null;
            }

            return(SaveCategory(toSiteId, toCateId, dto));
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="category"></param>
        /// <param name="pageIndex"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public string GetCategory(CategoryDto category, int pageIndex)
        {
            var tplId = GetCategoryTemplateId(category);


            //
            //todo:  /news/news/news/时候仍然能访问
            //

            //用于当前的模板共享数据
            //Cms.Context.Items["category.tag"] = category.Tag;
            Cms.Context.Items["category.path"] = category.Path;
            Cms.Context.Items["module.id"]     = category.ModuleId;
            Cms.Context.Items["page.index"]    = pageIndex;

            string title;

            if (pageIndex == 1)
            {
                title = !string.IsNullOrEmpty(category.PageTitle) ? category.PageTitle : $"{category.Name}_{_site.Title}";
            }
            else
            {
                switch (_site.Language)
                {
                case Languages.zh_CN:
                    title = $"- 第{pageIndex}页";
                    break;

                default:
                case Languages.en_US:
                    title = "- page " + pageIndex;
                    break;
                }

                title = $"{category.Name}{title}_{_site.Title}";
            }

            //解析模板
            return(PageUtility.Require(tplId, page =>
            {
                page.AddVariable("site", _site);
                page.AddVariable("page", new PageVariable
                {
                    Title = title,
                    SubTitle = _site.Title,
                    Keywords = category.Keywords,
                    Description = category.Description,
                    PageIndex = pageIndex
                });
                page.AddVariable("category", category);
                page.AddVariable("module", new Module {
                    ID = category.ModuleId
                });
            }));
        }
예제 #3
0
        public IEnumerable <CategoryDto> GetCategories(int siteId)
        {
            var site       = _repo.GetSiteById(siteId);
            var categories = site.Categories;

            foreach (var category in categories)
            {
                yield return(CategoryDto.ConvertFrom(category));
            }
        }
예제 #4
0
        public CategoryDto GetCategory(int siteId, string catPath)
        {
            // 如果以"/"开头,则去掉
            if (!string.IsNullOrEmpty(catPath) && catPath[0] == '/')
            {
                catPath = catPath.Substring(1);
            }
            var site = _repo.GetSiteById(siteId);

            return(CategoryDto.ConvertFrom(site.GetCategoryByPath(catPath)));
        }
예제 #5
0
        public IEnumerable <CategoryDto> GetCategories(
            int siteId, string catPath)
        {
            var site = repo.GetSiteById(siteId);
            var ic   = _categoryRep.GetCategoryByPath(siteId, catPath);

            if (ic == null)
            {
                yield break;
            }
            foreach (var category in ic.NextLevelChilds)
            {
                yield return(CategoryDto.ConvertFrom(category));
            }
        }
예제 #6
0
        /// <summary>
        /// 获取栏目的模板Id
        /// </summary>
        /// <param name="category"></param>
        /// <returns></returns>
        private string GetCategoryTemplateId(CategoryDto category)
        {
            if (category.CategoryTemplate != null)
            {
                if (category.CategoryTemplate.StartsWith("templates"))
                {
                    return("/" + GetTemplateId(category.CategoryTemplate));
                }
                else
                {
                    return(FormatTemplatePath(category.CategoryTemplate.Replace(".html", "")));
                }
            }

            //设置默认的模板
            return(FormatTemplatePath("category"));
        }
예제 #7
0
        private IEnumerable <ArchiveDto> GetArchiveEnumertor(IEnumerable <IArchive> archives)
        {
            IDictionary <int, CategoryDto> categories = new Dictionary <int, CategoryDto>();
            ArchiveDto  archive;
            CategoryDto cateDto;
            int         categoryId;

            foreach (var ia in archives)
            {
                var av = ia.Get();
                archive = new ArchiveDto
                {
                    StrId       = av.StrId,
                    Id          = ia.GetAggregaterootId(),
                    PublisherId = av.AuthorId,
                    Alias       = av.Alias,
                    Agree       = av.Agree,
                    Disagree    = av.Disagree,
                    Content     = av.Content,
                    CreateTime  = TimeUtils.UnixTime(av.CreateTime),
                    Tags        = av.Tags,
                    UpdateTime  = TimeUtils.UnixTime(av.UpdateTime),
                    Source      = av.Source,
                    Thumbnail   = av.Thumbnail,
                    Title       = av.Title,
                    SmallTitle  = av.SmallTitle,
                    Location    = av.Location,
                    ViewCount   = av.ViewCount,
                    Outline     = av.Outline,
                    //TemplateBind=null,
                    ExtendValues = ia.GetExtendValues()
                };

                //archive = new ArchiveDto().CloneData(ia);
                //archive.ID = ia.ID;

                if (!categories.TryGetValue(categoryId = ia.Category.GetDomainId(), out cateDto))
                {
                    cateDto = CategoryDto.ConvertFrom(ia.Category);
                    categories.Add(categoryId, cateDto);
                }

                archive.Category = cateDto;
                yield return(archive);
            }
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="siteId"></param>
        /// <param name="catPath"></param>
        /// <returns></returns>
        public IEnumerable <CategoryDto> GetCategories(int siteId, string catPath)
        {
            var       site = _repo.GetSiteById(siteId);
            ICategory ic   = catPath == "root" || String.IsNullOrEmpty(catPath)
                ? this._categoryRep.CreateCategory(new CmsCategoryEntity {
                SiteId = siteId, ParentId = 0
            })
                : this._categoryRep.GetCategoryByPath(siteId, catPath);

            if (ic == null)
            {
                yield break;
            }
            foreach (var category in ic.NextLevelChildren)
            {
                yield return(CategoryDto.ConvertFrom(category));
            }
        }
예제 #9
0
        public Result SaveCategory(int siteId, int parentId, CategoryDto category)
        {
            var       site = _repo.GetSiteById(siteId);
            ICategory ic   = null;

            if (category.ID > 0)
            {
                ic = site.GetCategory(category.ID);
            }
            if (ic == null)
            {
                ic = _categoryRep.CreateCategory(new CmsCategoryEntity());
            }
            var 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;
            var err = ic.Set(cat);

            if (err == null)
            {
                // 保存模板
                var 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

            var r = new Result();
            if (err == null)
            {
                var mp = new Dictionary <string, string>
                {
                    ["CategoryId"] = ic.GetDomainId().ToString()
                };
                r.Data = mp;
            }
            else
            {
                r.ErrCode = 1;
                r.ErrMsg  = err.Message;
            }

            return(r);
        }
예제 #10
0
        public CategoryDto GetCategoryByName(int siteId, string categoryName)
        {
            var site = _repo.GetSiteById(siteId);

            return(CategoryDto.ConvertFrom(site.GetCategoryByName(categoryName)));
        }
예제 #11
0
        public CategoryDto GetCategory(int siteId, int categoryId)
        {
            var site = _repo.GetSiteById(siteId);

            return(CategoryDto.ConvertFrom(site.GetCategory(categoryId)));
        }