【发布时间】:2019-03-14 03:58:21
【问题描述】:
我的申请页面上有很多活动可供注册。此方法返回所有活动事件。但是有一个问题,比如今天上午11点有一个活动。上午 11 点之后,它在逻辑上不应该显示,但它显示为活动。它直到午夜之后才隐藏起来。因此,当日期更改时(即期末不考虑小时数),它会变为非活动状态......更改 DateTime 以使事件在给定小时后变为非活动状态的最佳方法是什么,而不是第二天?
public IPagedList<Domain.Event> SearchEventsPublic(long[] eventCategoryTypeIds = null,
long[] locationIds = null,
DateTime? startDate = null,
DateTime? endDate = null,
int pageIndex = 0,
int pageSize = int.MaxValue)
{
var query = _eventRepository.Table;
// get event by filter
if (eventCategoryTypeIds != null && eventCategoryTypeIds.Length > 0)
query = query.Where(c => eventCategoryTypeIds.Contains(c.EventCategoryId));
if (locationIds != null && locationIds.Length > 0)
query = query.Where(c => locationIds.Contains(c.LocationId));
var minDate = DateTime.Now;
if (startDate.HasValue && startDate.Value > minDate)
{
minDate = startDate.Value.Date;
}
query = query.Where(c => c.StartDateTime >= minDate ||
(c.PrePurchase && (c.ParentId == null || c.ParentId == 0)));
if (endDate.HasValue)
{
var maxDate = endDate.Value.Date.AddDays(1).AddTicks(-1);
query = query.Where(c => c.StartDateTime <= maxDate ||
(c.PrePurchase && (c.ParentId == null || c.ParentId == 0)));
}
query = query.OrderBy(c => c.PrePurchase ? 0 : 1).ThenBy(c => c.StartDateTime);
return new PagedList<Domain.Event>(query.AsQueryable(), pageIndex, pageSize);
}
【问题讨论】:
-
minDate = startDate.Value.Date;你认为.Date会做什么?