本周
(n => n.date > DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.Date.DayOfWeek)))
重点说明: DateTime.Now.Date.DayOfWeek返回当前星期几
本月
(n => n.date > DateTime.Now.AddDays(-Convert.ToInt32(DateTime.Now.Date.Day)))
完整代码演示
/// <summary>
/// 管理后台首页-订单卡片 数据
/// </summary>
/// <returns></returns>
[HttpGet]
public async Task<GetCardOrderDataResponse> GetCardOrderData()
{
var yesterdayU = _businessAuditLogRepository.NoTrackingEntities
.Where(x => x.Type == BusinessAuditLogType.Unpackbox.TryToInt())
.Take(7)
.OrderByDescending(x => x.Id)
.AsEnumerable()
.Where(x => x.CreateTime.Date == DateTime.Now.AddDays(-1).Date)
.Count();
var todayU= _businessAuditLogRepository.NoTrackingEntities
.Where(x => x.Type == BusinessAuditLogType.Unpackbox.TryToInt())
.Take(7)
.OrderByDescending(x => x.Id)
.Where(x => x.CreateTime.Date == DateTime.Today.Date)
.Count();
var yesterdayS = _businessAuditLogRepository.NoTrackingEntities
.Where(x => x.Type == BusinessAuditLogType.StoringPackage.TryToInt())
.Take(7)
.OrderByDescending(x => x.Id)
.AsEnumerable()
.Where(x => x.CreateTime.Date== DateTime.Now.AddDays(-1).Date)
.Count();
var todayS = _businessAuditLogRepository.NoTrackingEntities
.Where(x => x.Type == BusinessAuditLogType.StoringPackage.TryToInt())
.Take(7)
.OrderByDescending(x => x.Id)
.AsEnumerable()
.Where(x => x.CreateTime.Date == DateTime.Now.Date)
.Count();
return await Task.FromResult(new GetCardOrderDataResponse()
{
TodayStoring = todayS,
TodayUnpack = todayU,
YesterdayStoring = yesterdayS,
YesterdayUnpack = yesterdayU
});
}
网友评论