修正 Entity Framework LINQ 查詢中的 .Date 屬性使用問題
This commit is contained in:
@@ -1340,7 +1340,11 @@ public class activityController : ApiController
|
||||
if (q.activity_num.HasValue && q.activity_num > 0)
|
||||
qry = qry.Where(o => o.activity_num == q.activity_num);
|
||||
if (q.check_time.HasValue)
|
||||
qry = qry.Where(o => o.reg_time.Value.Date == q.check_time.Value.Date);
|
||||
{
|
||||
var checkDate = q.check_time.Value.Date;
|
||||
var checkDateEnd = checkDate.AddDays(1);
|
||||
qry = qry.Where(o => o.reg_time >= checkDate && o.reg_time < checkDateEnd);
|
||||
}
|
||||
|
||||
|
||||
if (sortBy.Equals("subject"))
|
||||
@@ -1461,7 +1465,7 @@ public class activityController : ApiController
|
||||
qry = qry.Where(o => o.reg_time < Convert.ToDateTime(q.reg_time2.Value).AddDays(1));
|
||||
|
||||
|
||||
qry = qry.Where(o => (_now >= o.startDate_solar && _now < o.endDate_lunar) || (_now < o.startDate_solar && o.dueDate.HasValue && o.dueDate.Value.Date.CompareTo(_now) <= 180));
|
||||
qry = qry.Where(o => (_now >= o.startDate_solar && _now < o.endDate_lunar) || (_now < o.startDate_solar && o.dueDate.HasValue && DbFunctions.DiffDays(o.dueDate, _now) <= 180));
|
||||
|
||||
qry = qry.OrderByDescending(o => o.num);
|
||||
|
||||
@@ -1474,9 +1478,16 @@ public class activityController : ApiController
|
||||
var r1 = qry.ToList();
|
||||
var r2 = r1.Select(x => new { num = x.num, subject = x.subject });
|
||||
var count = qry.Count();
|
||||
|
||||
// 計算昨天和今天的日期範圍
|
||||
var yesterdayStart = _now.Date.AddDays(-1);
|
||||
var yesterdayEnd = _now.Date;
|
||||
var todayStart = _now.Date;
|
||||
var todayEnd = _now.Date.AddDays(1);
|
||||
|
||||
var ret = new
|
||||
{
|
||||
list = qry.ToList().Select(x => new
|
||||
list = r1.Select(x => new
|
||||
{
|
||||
num = x.num,
|
||||
subject = x.subject,
|
||||
@@ -1485,9 +1496,9 @@ public class activityController : ApiController
|
||||
startDate_lunar = x.startDate_lunar,
|
||||
endDate_lunar = x.endDate_lunar,
|
||||
order_qty = x.pro_order.Count(),
|
||||
check_qty_yest = x.activity_check.Where(c => _now.Date.CompareTo(c.reg_time?.Date) == 1).Count(),
|
||||
check_qty_today = x.activity_check.Where(c => _now.Date.CompareTo(c.reg_time?.Date) == 0).Count(),
|
||||
status = (_now >= x.startDate_solar && _now < x.endDate_lunar) ? "進行中" : ((_now < x.startDate_solar && x.dueDate?.Date.CompareTo(_now) <= 180) ? "報名中" : "") //進行中: 活動日期已開始,未結束 ; 報名中: 未開始,報名未截止近半年(?)的活動
|
||||
check_qty_yest = x.activity_check.Where(c => c.reg_time.HasValue && c.reg_time.Value >= yesterdayStart && c.reg_time.Value < yesterdayEnd).Count(),
|
||||
check_qty_today = x.activity_check.Where(c => c.reg_time.HasValue && c.reg_time.Value >= todayStart && c.reg_time.Value < todayEnd).Count(),
|
||||
status = (_now >= x.startDate_solar && _now < x.endDate_lunar) ? "進行中" : ((_now < x.startDate_solar && x.dueDate.HasValue && (x.dueDate.Value - _now).Days <= 180) ? "報名中" : "") //進行中: 活動日期已開始,未結束 ; 報名中: 未開始,報名未截止近半年(?)的活動
|
||||
|
||||
}),
|
||||
count = count
|
||||
|
||||
Reference in New Issue
Block a user