获取通知信息 API - GetId
public async Task<ApiResult> GetId(int id)
{
if (id <= 0 || id > 9999)
{
//获取最近的一条
var data = await _db.ContentNotices
.Where(x => x.Status == 1)
.OrderByDescending(x => x.Sort)
.Select(x => new NoticeInfoRes
{
Id = x.Id,
Time = x.Time.ToString("yyyy-MM-dd"),
Title = x.Title,
Content = x.Content
})
.FirstOrDefaultAsync();
return Api.Ok(data);
}
var notice = await _notice.GetById(id);
if (notice == null)
{
var recentNotice = await _db.ContentNotices
.Where(x => x.Status == 1)
.OrderByDescending(x => x.Sort)
.Select(x => new NoticeInfoRes
{
Id = x.Id,
Time = x.Time.ToString("yyyy-MM-dd"),
Title = x.Title,
Content = x.Content
})
.FirstOrDefaultAsync();
return Api.Ok(recentNotice);
}
else
{
var res = new NoticeInfoRes
{
Id = notice.Id,
Time = notice.Time.ToString("yyyy-MM-dd"),
Title = notice.Title,
Content = notice.Content
};
return Api.Ok(res);
}
}
原文地址: https://www.cveoy.top/t/topic/lwLr 著作权归作者所有。请勿转载和采集!