Exemple #1
0
        public Result SaveArchive(int siteId, int catId, ArchiveDto archiveDto)
        {
            var value = archiveDto.ToArchiveEntity();

            value.CatId  = catId;
            value.SiteId = siteId;
            var      ic = _contentRep.GetContent(siteId);
            IArchive ia;

            if (archiveDto.Id <= 0)
            {
                ia = ic.CreateArchive(new CmsArchiveEntity());
            }
            else
            {
                ia = ic.GetArchiveById(archiveDto.Id);
            }

            var err = ia.Set(value);

            if (err == null)
            {
                // 更新模板
                if (!string.IsNullOrEmpty(archiveDto.TemplatePath))
                {
                    ia.SetTemplatePath(archiveDto.TemplatePath);
                }
                // 设置扩展属性
                err = ia.SetExtendValue(archiveDto.ExtendValues);
                // 保存文档
                if (err == null)
                {
                    err = ia.Save();
                }
            }

            var r = new Result();

            if (err == null)
            {
                r.Data = new Dictionary <string, string>();
                r.Data.Add("ArchiveId", ia.GetAggregaterootId().ToString());
            }
            else
            {
                r.ErrCode = 1;
                r.ErrMsg  = err.Message;
            }

            return(r);
        }
Exemple #2
0
        public Result SaveExtendField(int siteId, ExtendFieldDto dto)
        {
            var site = repo.GetSiteById(siteId);

            if (site == null)
            {
                throw new Exception("站点不存在");
            }

            var field = _extendRep.CreateExtendField(dto.Id, dto.Name);

            field.CloneData(dto);
            var err = site.GetExtendManager().SaveExtendField(field);
            var r   = new Result();

            if (err != null)
            {
                r.ErrCode = 1;
                r.ErrMsg  = err.Message;
            }

            return(r);
        }
Exemple #3
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)
            {
                r.Data = new Dictionary <string, string>();
                r.Data["CategoryId"] = ic.GetDomainId().ToString();
            }
            else
            {
                r.ErrCode = 1;
                r.ErrMsg  = err.Message;
            }

            return(r);
        }