【新增】WebApi文章Controller新增【获取最新文章】【获取文章栏目】两个接口

This commit is contained in:
大灰灰
2022-11-29 01:19:55 +08:00
parent 30f1082e06
commit 9e5232762a
7 changed files with 157 additions and 17 deletions

View File

@@ -10,6 +10,7 @@
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using CoreCms.Net.IRepository;
@@ -128,5 +129,41 @@ namespace CoreCms.Net.Repository
#endregion
#region
/// <summary>
/// 重写根据条件查询分页数据
/// </summary>
/// <param name="predicate">判断集合</param>
/// <param name="orderByType">排序方式</param>
/// <param name="orderByExpression"></param>
/// <param name="take"></param>
/// <returns></returns>
public async Task<List<CoreCmsArticle>> QueryListAsync(Expression<Func<CoreCmsArticle, bool>> predicate,
Expression<Func<CoreCmsArticle, object>> orderByExpression, OrderByType orderByType,int take)
{
var list = await DbClient.Queryable<CoreCmsArticle>()
.OrderByIF(orderByExpression != null, orderByExpression, orderByType)
.WhereIF(predicate != null, predicate).Select(p => new CoreCmsArticle
{
id = p.id,
title = p.title,
brief = p.brief,
coverImage = p.coverImage,
typeId = p.typeId,
sort = p.sort,
isPub = p.isPub,
isDel = p.isDel,
pv = p.pv,
createTime = p.createTime,
updateTime = p.updateTime
}).Take(take).ToListAsync();
return list;
}
#endregion
}
}