/// <summary> /// 获取用户所有落在某个时间段的日程表事件,只要是起始时间或结束时间在指定范围都算 /// </summary> /// <param name="userId">用户ID</param> /// <param name="startTime">起始时间</param> /// <param name="endTime">结束时间</param> /// <returns></returns> public IEnumerable <EventModel> GetEvents(int userId, DateTime startTime, DateTime endTime) { //转为yyyy-MM-dd HH:mm:ss标准格式以便在数据库中以字符串数据规则进行比对 string starts = CommOp.ToTimeStr(startTime); string ends = CommOp.ToTimeStr(endTime); int startTimeId = SiteManager.Catalog.GetExtId(ScheduleEvent.Root.Id, ScheduleEvent.Root.StartTime); int endTimeId = SiteManager.Catalog.GetExtId(ScheduleEvent.Root.Id, ScheduleEvent.Root.EndTime); int alertBeforeId = SiteManager.Catalog.GetExtId(ScheduleEvent.Root.Id, ScheduleEvent.Root.AlertBefore); int urlId = SiteManager.Catalog.GetExtId(ScheduleEvent.Root.Id, ScheduleEvent.Root.ProcessUrl); return(_article.GetAllInCatalog(ScheduleEvent.Root.Id) .Where(ca => ca.Article.EditorId == userId //不是属于通知 && ca.Article.Options < ScheduleEvent.OptionNotice) .Select(ca => new EventModel { start = ca.Article.Exts.FirstOrDefault(ext => ext.CatlogExtId == startTimeId).Value, end = ca.Article.Exts.FirstOrDefault(ext => ext.CatlogExtId == endTimeId).Value, caId = ca.Id, title = ca.Article.Title, alertBefore = ca.Article.Exts.FirstOrDefault(ext => ext.CatlogExtId == alertBeforeId).Value, editable = ca.Article.Options == ScheduleEvent.OptionReadOnly, finished = ca.Article.State == ScheduleEvent.EventFinished, url = ca.Article.Exts.FirstOrDefault(ext => ext.CatlogExtId == urlId).Value, }) .Where(r => (r.start != null && starts.CompareTo(r.start) <= 0 && ends.CompareTo(r.start) >= 0) || (r.end != null && starts.CompareTo(r.end) <= 0 && ends.CompareTo(r.end) >= 0)) .ToList()); }