예제 #1
0
        Base_Article Clone(Base_Article article)
        {
            Base_Article newArt = new Base_Article
            {
                Abstract   = article.Abstract,
                Author     = article.Author,
                Exts       = article.Exts.Select(ext => Clone(ext)).ToList(),
                Clicks     = article.Clicks,
                CreateTime = article.CreateTime,
                EditorId   = article.EditorId,
                EditTime   = article.EditTime,
                Id         = article.Id,
                Keywords   = article.Keywords,
                State      = article.State,
                Targets    = article.Targets.Select(tar => Clone(tar)).ToList(),
                Title      = article.Title,
                UrlTitle   = article.UrlTitle
            };

            if (article.ArticleText != null)
            {
                newArt.ArticleText = new Base_ArticleText
                {
                    Id   = article.ArticleText.Id,
                    Text = article.ArticleText.Text,
                };
            }

            return(newArt);
        }
예제 #2
0
        /// <summary>
        /// 根据栏目ID新建一篇文章,并建立和栏目对应的文章标签
        /// </summary>
        /// <param name="catId">栏目ID</param>
        /// <returns>新文章对象</returns>e
        public Base_CatalogArticle CreateByCatalog(int catId)
        {
            Base_Article art = new Base_Article()
            {
                CreateTime = DateTime.Now,
                EditTime   = DateTime.Now,
            };

            Base_CatalogArticle ca = new Base_CatalogArticle
            {
                CatalogId = catId,
                Article   = art
            };

            //保持文件的扩展属性和文件夹的保持一致
            foreach (Base_CatalogExt ext in SiteManager.Catalog.GetAllExts(catId))
            {
                art.Exts.Add(new Base_ArticleExt
                {
                    Article     = art,
                    CatlogExtId = ext.Id,
                    Value       = ext.DefaultValue
                });
            }

            return(ca);
        }
예제 #3
0
        /// <summary>
        /// 判断某文章的UrlTitle(对Url友好的标题)是否在本栏目内是重复的
        /// </summary>
        /// <param name="catId"></param>
        /// <param name="article"></param>
        /// <returns></returns>
        public bool IsUrlTitleExists(int catId, Base_Article article)
        {
            var urlTitles = article.Id == 0 ? GetAllInCatalog(catId).Where(art => !string.IsNullOrEmpty(art.Article.UrlTitle)).Select(art => art.Article.UrlTitle)
                   : GetAllInCatalog(catId).Where(art => (!string.IsNullOrEmpty(art.Article.UrlTitle) && (art.Id != article.Id))).Select(art => art.Article.UrlTitle);

            return(urlTitles.Contains(article.UrlTitle));
        }
예제 #4
0
        public static object GetExt(this Base_Article article, Base_CatalogExt catExt)
        {
            if (catExt == null)
            {
                return(null);
            }
            var artExt = article.Exts.FirstOrDefault(ext => ext.CatlogExtId == catExt.Id);

            if (artExt == null)
            {
                return(null);
            }

            switch ((ExtDataType)catExt.DataType)
            {
            case ExtDataType.Currency:
                return(CommOp.ToDecimalNull(artExt.Value));

            case ExtDataType.DateAndTime:
            case ExtDataType.Date:
                return(CommOp.ToDateTimeNull(artExt.Value));

            case ExtDataType.SingleNumber:
                return(CommOp.ToIntNull(artExt.Value));

            case ExtDataType.Bool:
                return(CommOp.ToBool(artExt.Value));

            default:
                return(artExt.Value);
            }
        }
예제 #5
0
 /// <summary>
 /// 获取某文章所属的静态栏目,它决定了文章的类型,它可能是某个文章栏目的上级栏目
 /// </summary>
 /// <param name="art"></param>
 /// <returns></returns>
 public Base_Catalog GetStaticCatalog(Base_Article art)
 {
     using (var article = SiteManager.Get <ArticleManager>())
     {
         var catIds = article.GetQuery().Where(ca => ca.ArticleId == art.Id)
                      .Select(ca => ca.CatalogId);
         foreach (var catId in catIds)
         {
             var cat = GetStaticParent(catId);
             if (cat != null)
             {
                 return(cat);
             }
         }
     }
     return(null);
 }
예제 #6
0
        public static object GetExt(this Base_Article article, int catExtId)
        {
            var catExt = SiteManager.Catalog.GetExtById(catExtId);

            return(GetExt(article, catExt));
        }
예제 #7
0
        public static object SetExt(this Base_Article article, Base_CatalogExt catExt, object value)
        {
            if (catExt == null)
            {
                return(null);
            }
            var artExt = article.Exts.FirstOrDefault(ext => ext.CatlogExtId == catExt.Id);

            if (artExt == null)
            {
                artExt = new Base_ArticleExt
                {
                    CatlogExtId = catExt.Id,
                };
                article.Exts.Add(artExt);
            }
            ;

            string strValue = null;

            switch ((ExtDataType)catExt.DataType)
            {
            case ExtDataType.Currency:
                Decimal?dec = CommOp.ToDecimalNull(value);
                if (dec != null)
                {
                    strValue = dec.Value.ToString();
                }
                break;

            case ExtDataType.FloatNumber:
                double?flt = CommOp.ToDoubleNull(value);
                if (flt != null)
                {
                    strValue = flt.Value.ToString();
                }
                break;

            case ExtDataType.DateAndTime:
            case ExtDataType.Date:
                DateTime?dt = CommOp.ToDateTimeNull(value);
                if (dt != null)
                {
                    strValue = dt.Value.ToString("yyyy-MM-dd HH:mm:ss");
                }
                break;

            case ExtDataType.SingleNumber:
                long?lng = CommOp.ToLongNull(value);
                if (lng != null)
                {
                    strValue = lng.Value.ToString();
                }
                break;

            case ExtDataType.Bool:
                value    = CommOp.ToBool(value);
                strValue = value.ToString();
                break;

            default:
                strValue = CommOp.ToStr(value);
                if (strValue.IsEmpty())
                {
                    strValue = null;
                }
                break;
            }
            artExt.Value = strValue;
            return(value);
        }
예제 #8
0
        public static object SetExt(this Base_Article article, int catExtId, object value)
        {
            var catExt = SiteManager.Catalog.GetExtById(catExtId);

            return(SetExt(article, catExt, value));
        }