예제 #1
0
        public CmsArchiveEntity ToArchiveEntity()
        {
            CmsArchiveEntity dst = new CmsArchiveEntity();

            dst.ID         = this.Id;
            dst.StrId      = this.StrId;
            dst.Alias      = this.Alias;
            dst.Path       = this.Path;
            dst.CatId      = this.Category.ID;
            dst.Flag       = this.Flag;
            dst.AuthorId   = this.PublisherId;
            dst.Title      = this.Title;
            dst.SmallTitle = this.SmallTitle;
            dst.Location   = this.Location;
            dst.Source     = this.Source;
            dst.Flag       = this.Flag;
            dst.Tags       = this.Tags;
            dst.Outline    = this.Outline;
            dst.Content    = this.Content;
            dst.ViewCount  = this.ViewCount;
            dst.Agree      = this.Agree;
            dst.Disagree   = this.Disagree;
            dst.Thumbnail  = this.Thumbnail;
            return(dst);
        }
예제 #2
0
파일: ArchiveDal.cs 프로젝트: lyfb/cms-1
        /// <summary>
        /// 插入文章并返回ID
        /// </summary>
        /// <returns></returns>
        public bool Add(CmsArchiveEntity e)
        {
            IDictionary <string, object> data = new Dictionary <string, object>();

            data.Add("@siteId", e.SiteId);
            data.Add("@strId", e.StrId);
            data.Add("@alias", e.Alias);
            data.Add("@catId", e.CatId);
            data.Add("@flag", e.Flag);
            data.Add("@path", e.Path);
            data.Add("@authorId", e.AuthorId);
            data.Add("@title", e.Title);
            data.Add("@smallTitle", e.SmallTitle ?? "");
            data.Add("@location", e.Location);
            data.Add("@sortNumber", e.SortNumber);
            data.Add("@source", e.Source ?? "");
            data.Add("@thumbnail", e.Thumbnail ?? "");
            data.Add("@outline", e.Outline ?? "");
            data.Add("@content", e.Content);
            data.Add("@tags", e.Tags ?? "");
            data.Add("@createTime", e.CreateTime);
            data.Add("@updateTime", e.UpdateTime);
            var rowcount = ExecuteNonQuery(CreateQuery(DbSql.ArchiveAdd, data));

            return(rowcount == 1);
        }
예제 #3
0
파일: ArchiveDto.cs 프로젝트: lyfb/cms-1
        public CmsArchiveEntity ToArchiveEntity()
        {
            var dst = new CmsArchiveEntity();

            dst.ID         = Id;
            dst.StrId      = StrId;
            dst.Alias      = Alias;
            dst.Path       = Path;
            dst.CatId      = Category.ID;
            dst.Flag       = Flag;
            dst.AuthorId   = PublisherId;
            dst.Title      = Title;
            dst.SmallTitle = SmallTitle;
            dst.Location   = Location;
            dst.Source     = Source;
            dst.Flag       = Flag;
            dst.Tags       = Tags;
            dst.Outline    = Outline;
            dst.Content    = Content;
            dst.ViewCount  = ViewCount;
            dst.Agree      = Agree;
            dst.Disagree   = Disagree;
            dst.Thumbnail  = Thumbnail;
            return(dst);
        }
예제 #4
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="a"></param>
        public void Update(CmsArchiveEntity e)
        {
            IDictionary <String, Object> data = new Dictionary <String, Object>();

            data.Add("@siteId", e.SiteId);
            data.Add("@strId", e.StrId);
            data.Add("@alias", e.Alias);
            data.Add("@catId", e.CatId);
            data.Add("@flag", e.Flag);
            data.Add("@path", e.Path);
            data.Add("@authorId", e.AuthorId);
            data.Add("@title", e.Title);
            data.Add("@smallTitle", e.SmallTitle ?? "");
            data.Add("@flags", e.Flags);
            data.Add("@location", e.Location);
            data.Add("@sortNumber", e.SortNumber);
            data.Add("@source", e.Source ?? "");
            data.Add("@thumbnail", e.Thumbnail ?? "");
            data.Add("@outline", e.Outline ?? "");
            data.Add("@content", e.Content);
            data.Add("@tags", e.Tags ?? "");
            data.Add("@updateTime", e.UpdateTime);
            data.Add("@id", e.ID);
            base.ExecuteNonQuery(base.CreateQuery(DbSql.ArchiveUpdate, data));
        }
예제 #5
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="contentRep"></param>
 /// <param name="archiveRep"></param>
 /// <param name="extendRep"></param>
 /// <param name="categoryRep"></param>
 /// <param name="templateRep"></param>
 /// <param name="linkRep"></param>
 /// <param name="id"></param>
 /// <param name="strId"></param>
 /// <param name="categoryId"></param>
 /// <param name="title"></param>
 /// <returns></returns>
 public IArchive CreateArchive(
     IContentRepository contentRep,
     IArchiveRepository archiveRep,
     IExtendFieldRepository extendRep,
     ICategoryRepo categoryRep,
     ITemplateRepo templateRep,
     CmsArchiveEntity value)
 {
     return(new Archive(contentRep, archiveRep, extendRep,
                        categoryRep, templateRep, value));
 }
예제 #6
0
 public Error SaveArchive(CmsArchiveEntity a)
 {
     if (a.ID <= 0)
     {
         _dal.Add(a);
         a.ID = _dal.GetMaxArchiveId(a.SiteId);
     }
     else
     {
         _dal.Update(a);
     }
     return(null);
 }
예제 #7
0
        public DataTransfer.Result SaveArchive(int siteId, int catId, ArchiveDto archiveDto)
        {
            CmsArchiveEntity value = archiveDto.ToArchiveEntity();

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

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

            Error 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();
                }
            }
            DataTransfer.Result r = new DataTransfer.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);
        }
예제 #8
0
        /// <summary>
        /// 转换文档传输对象
        /// </summary>
        /// <param name="archive">文档</param>
        /// <param name="copyCategory"></param>
        /// <param name="copyTemplate"></param>
        /// <param name="copyExtend"></param>
        /// <returns></returns>
        public static ArchiveDto ConvertFrom(IArchive archive, bool copyCategory, bool copyTemplate, bool copyExtend)
        {
            CmsArchiveEntity a   = archive.Get();
            ArchiveDto       dto = new ArchiveDto
            {
                Id          = archive.GetAggregaterootId(),
                StrId       = a.StrId,
                Disagree    = a.Disagree,
                Agree       = a.Agree,
                UpdateTime  = TimeUtils.UnixTime(a.UpdateTime),
                CreateTime  = TimeUtils.UnixTime(a.CreateTime),
                Content     = a.Content,
                Alias       = a.Alias,
                PublisherId = a.AuthorId,
                Flag        = a.Flag,
                Outline     = a.Outline,
                Source      = a.Source,
                Tags        = a.Tags,
                Url         = a.Path,
                Location    = a.Location,
                Thumbnail   = a.Thumbnail,
                Title       = a.Title,
                SmallTitle  = a.SmallTitle,
                ViewCount   = a.ViewCount,
            };

            if (copyCategory)
            {
                CategoryDto categoryDto = CategoryDto.ConvertFrom(archive.Category);
                categoryDto.ID = archive.Category.GetDomainId();
                dto.Category   = categoryDto;
            }

            if (copyExtend)
            {
                dto.ExtendValues = archive.GetExtendValues();
            }

            if (copyTemplate)
            {
                if (archive.Template != null)// && archive.Template.BindRefrenceId == archive.ID)
                {
                    dto.TemplatePath   = archive.Template.TplPath;
                    dto.IsSelfTemplate = archive.Template.BindRefrenceId == archive.GetAggregaterootId();
                }
            }
            return(dto);
        }
예제 #9
0
        private IEnumerable <ArchiveDto> GetArchiveEnumertor(IEnumerable <IArchive> archives)
        {
            IDictionary <int, CategoryDto> categories = new Dictionary <int, CategoryDto>();
            ArchiveDto  archive;
            CategoryDto cateDto;
            int         categoryId;

            foreach (IArchive ia in archives)
            {
                CmsArchiveEntity 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),
                    Flags       = av.Flags,
                    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);
            }
        }
예제 #10
0
 internal Archive(
     IContentRepository contentRep,
     IArchiveRepository archiveRep,
     IExtendFieldRepository extendRep,
     ICategoryRepo categoryRep,
     ITemplateRepo templateRep,
     CmsArchiveEntity value)
     : base(
         contentRep,
         extendRep,
         categoryRep,
         templateRep
         )
 {
     this._value       = value;
     this._archiveRep  = archiveRep;
     this._templateRep = templateRep;
     this._catRepo     = categoryRep;
 }
예제 #11
0
        private Error SwapSortNumber(IArchive src)
        {
            if (src == null)
            {
                return(null);
            }
            CmsArchiveEntity sv = src.Get();
            int sortN           = sv.SortNumber;

            sv.SortNumber = this._value.SortNumber;
            Error err = src.Set(sv);

            if (err == null)
            {
                src.Save();
            }
            this._value.SortNumber = sortN;
            return(this.Save());
        }
예제 #12
0
        public void TestSaveArchive()
        {
            IArchive         ia  = this.archiveRepo.GetArchiveById(1, 3);
            CmsArchiveEntity v   = ia.Get();
            Error            err = ia.Set(v);

            if (err == null)
            {
                ia.SetTemplatePath("archive");
                err = ia.Save();
            }
            if (err != null)
            {
                Assert.Fail(err.Message);
            }
            else
            {
                this.Println(this.Stringfy(ia.Get()));
            }
        }
예제 #13
0
 public IArchive CreateArchive(CmsArchiveEntity value)
 {
     return(_archiveRep.CreateArchive(value));
 }
예제 #14
0
        public Error Set(CmsArchiveEntity src)
        {
            this._value.ID         = src.ID;
            this._value.StrId      = src.StrId;
            this._value.SiteId     = src.SiteId;
            this._value.Alias      = src.Alias;
            this._value.CatId      = src.CatId;
            this._value.Path       = src.Path;
            this._value.Flag       = src.Flag;
            this._value.AuthorId   = src.AuthorId;
            this._value.Title      = src.Title;
            this._value.SmallTitle = src.SmallTitle;
            this._value.Location   = src.Location;
            this._value.Source     = src.Source;
            this._value.Tags       = src.Tags;
            this._value.Outline    = src.Outline;
            this._value.Content    = src.Content;
            this._value.ViewCount  = src.ViewCount;
            this._value.Agree      = src.Agree;
            this._value.Disagree   = src.Disagree;
            this._value.UpdateTime = src.UpdateTime;
            this._value.CreateTime = src.CreateTime;
            this._value.Thumbnail  = src.Thumbnail;
            int unix = TimeUtils.Unix(DateTime.Now);

            this._value.UpdateTime = unix;

            if (this.GetAggregaterootId() <= 0)
            {
                if (src.SiteId <= 0)
                {
                    return(new Error("参数错误:SiteId"));
                }
                if (this._value.CatId < 0)
                {
                    return(new Error("参数错误:CatId"));
                }
                this._value.SiteId     = src.SiteId;
                this._value.CatId      = src.CatId;
                this._value.CreateTime = unix;
                // 生成5位随机ID
                string strId;
                do
                {
                    strId = IdGenerator.GetNext(5);              //创建5位ID
                } while (this._archiveRep.CheckSidIsExist(this._value.SiteId, strId));
                this._value.StrId = strId;
            }
            ICategory ic = this.Category;

            if (ic == null)
            {
                return(new Error("栏目不存在"));
            }
            // 如果设置了别名,检测路径是缶匹配
            if (!String.IsNullOrEmpty(src.Alias))
            {
                String path    = this.CombineArchivePath();
                bool   isMatch = this._archiveRep.CheckPathMatch(this._value.SiteId, path, this.GetAggregaterootId());
                if (!isMatch)
                {
                    return(new Error("文档路径已存在"));
                }
            }
            if (src.SortNumber > 0)
            {
                this._value.SortNumber = src.SortNumber;
            }
            return(null);
        }
예제 #15
0
        private IArchive CreateArchiveFromDataReader(DbDataReader rd, IndexOfHandler <String> indexOf)
        {
            CmsArchiveEntity archive = new CmsArchiveEntity();

            if (indexOf("id") != -1)
            {
                archive.ID = Convert.ToInt32(rd["id"] ?? "0");
            }
            if (indexOf("cat_id") != -1)
            {
                archive.CatId = Convert.ToInt32(rd["cat_id"]);
            }
            if (indexOf("title") != -1)
            {
                archive.Title = (rd["title"] ?? "").ToString();
            }
            if (indexOf("flag") != -1)
            {
                archive.Flag = Convert.ToInt32(rd["flag"] ?? "0");
            }
            if (indexOf("path") != -1)
            {
                archive.Path = (rd["path"] ?? "").ToString();
            }
            if (indexOf("alias") != -1)
            {
                archive.Alias = (rd["alias"] ?? "").ToString();
            }
            if (indexOf("str_id") != -1)
            {
                archive.StrId = (rd["str_id"] ?? "").ToString();
            }
            if (indexOf("site_id") != -1)
            {
                archive.SiteId = Convert.ToInt32(rd["site_id"]);
            }
            if (indexOf("small_title") != -1)
            {
                archive.SmallTitle = (rd["small_title"] ?? "").ToString();
            }
            if (indexOf("location") != -1)
            {
                archive.Location = rd["location"].ToString();
            }
            if (indexOf("sort_number") != -1)
            {
                archive.SortNumber = int.Parse(rd["sort_number"].ToString());
            }
            if (indexOf("outline") != -1)
            {
                archive.Outline = (rd["outline"] ?? "").ToString();
            }
            if (indexOf("author_id") != -1)
            {
                archive.AuthorId = rd["author_id"] == DBNull.Value ? 0 : Convert.ToInt32(rd["author_id"]);
            }
            if (indexOf("content") != -1)
            {
                archive.Content = rd["content"].ToString();
            }
            if (indexOf("source") != -1)
            {
                archive.Source = (rd["source"] ?? "").ToString();
            }
            if (indexOf("tags") != -1)
            {
                archive.Tags = (rd["tags"] ?? "").ToString();
            }
            if (indexOf("thumbnail") != -1)
            {
                archive.Thumbnail = (rd["thumbnail"] ?? "").ToString();
            }
            if (indexOf("create_time") != -1)
            {
                archive.CreateTime = Convert.ToInt32(rd["create_time"]);
            }
            if (indexOf("update_time") != -1)
            {
                archive.UpdateTime = Convert.ToInt32(rd["update_time"]);
            }
            if (indexOf("view_count") != -1)
            {
                archive.ViewCount = int.Parse((rd["view_count"] ?? "0").ToString());
            }
            //archive.Agree = int.Parse((rd["agree"] ?? "0").ToString());
            //archive.Disagree = int.Parse((rd["disagree"] ?? "0").ToString());

            //rd.CopyToEntity(archive);
            return(this.CreateArchive(archive));
        }
예제 #16
0
 public IArchive CreateArchive(CmsArchiveEntity value)
 {
     return(base.CreateArchive(this._contentRep, this, this._extendRep, this._categoryRep, this._templateRep, value));
 }