增加文章方法,上下篇

This commit is contained in:
2019-01-08 22:04:12 +08:00
parent 9e123b3c68
commit 61b72ca349
2 changed files with 88 additions and 0 deletions
+59
View File
@@ -153,6 +153,65 @@ namespace COMCMS.Core
#endregion
#region 业务操作
/// <summary>
/// 获取上一条记录/前一条记录
/// </summary>
/// <param name="id">ID</param>
/// <returns></returns>
public static Article GetPrev(int id)
{
Article entity = Article.FindById(id);
if (entity != null)
{
//获取上一条记录
IList<Article> list = Article.FindAll(_.Id > entity.Id & _.KId == entity.KId & _.Sequence <= entity.Sequence, string.Format("{0} Desc,{1} Asc", _.Sequence, _.Id), null, 0, 1);
if (list != null && list.Count > 0)
return list[0];
else
{
list = Article.FindAll(_.Id != entity.Id & _.KId == entity.KId & _.Sequence < entity.Sequence, string.Format("{0} Desc,{1} Asc", _.Sequence, _.Id), null, 0, 1);
if (list != null && list.Count > 0)
{
return list[0];
}
else
return null;
}
}
else
return null;
}
/// <summary>
/// 获取下一条记录/后一条记录
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public static Article GetNext(int id)
{
Article entity = Article.FindById(id);
if (entity != null)
{
//获取上一条记录
IList<Article> list = Article.FindAll(_.Id != entity.Id & _.KId == entity.KId & _.Sequence > entity.Sequence, string.Format("{0} Asc,{1} Desc", _.Sequence, _.Id), null, 0, 1);
if (list != null && list.Count > 0)
return list[0];
else
{
list = Article.FindAll(_.Id < entity.Id & _.KId == entity.KId & _.Sequence >= entity.Sequence, string.Format("{0} Asc,{1} Desc", _.Sequence, _.Id), null, 0, 1);
if (list != null && list.Count > 0)
{
return list[0];
}
else
return null;
}
}
else
return null;
}
#endregion
}
}
+29
View File
@@ -325,6 +325,35 @@ namespace COMCMS.Core
}
}
}
/// <summary>
/// 获取当前位置
/// </summary>
/// <param name="kid">类别ID</param>
/// <returns></returns>
public static string GetNav(int kid)
{
string tpl = "<a href=\"{0}\" title=\"{1}\">{1}</a>";
string re = string.Empty;
ArticleCategory model = Find(_.Id == kid);
if (model == null)
{
re = string.Format(tpl, "/", "首页") + re;//查到最后肯定是没有
}
else
{
re += " &gt; " + string.Format(tpl, "/article/index/" + model.Id, model.KindName);
if (model.PId != 0)
{
re = GetNav(model.PId) + re;
}
else
{
re = string.Format(tpl, "/", "首页") + re;//查到最后肯定是没有
}
}
return re;
}
#endregion
}
}