public BlockedPeriod FindBlockedPeriodByDate(DateTime date) { TimeSpan now = timeManager.Now().TimeOfDay; return(BlockedPeriods.GetAll().Where(b => b.EndDatetime.Date > date && b.StartDatetime.Date <= date || b.EndDatetime.Date == date && b.EndDatetime.TimeOfDay > now) .OrderByDescending(b => b.StartDatetime).FirstOrDefault()); }
private bool IsInBlockedPeriod(DateTime date, Timeslot timeslot) { DateTime timeslotStart = date + timeslot.StartTime; DateTime timeslotEnd = date + timeslot.EndTime; // Check if the start or end of the timeslot is inside any blocked period return(BlockedPeriods.Query().Where(bp => (timeslotStart >= bp.StartDatetime && timeslotStart <= bp.EndDatetime) || (timeslotEnd >= bp.StartDatetime && timeslotEnd <= bp.EndDatetime) ).Any()); // Different flavor, same functionality. Choose one. return(BlockedPeriods.Query().Where(bp => (date > bp.StartDatetime && date < bp.EndDatetime) || (date == bp.StartDatetime.Date && bp.StartDatetime.TimeOfDay >= timeslot.StartTime) || (date == bp.EndDatetime.Date && bp.EndDatetime.TimeOfDay <= timeslot.EndTime)) .Any()); }
public void AddBlockedPeriod(BlockedPeriod blockedPeriod) { BlockedPeriods.Add(blockedPeriod); BlockedPeriods.SaveChanges(); }
public BlockedPeriod GetBlockedPeriodById(int blockId) { return(BlockedPeriods.GetAll().Where(b => b.Id == blockId).FirstOrDefault()); }
public void DeleteBlockedPeriod(BlockedPeriod blockedPeriod) { BlockedPeriods.Delete(blockedPeriod); BlockedPeriods.SaveChanges(); }
public IList <BlockedPeriod> GetAllBlockedPeriodsFuture() { DateTime now = timeManager.Now(); return(BlockedPeriods.GetAll().Where(b => b.EndDatetime > now).OrderByDescending(b => b.StartDatetime).ToList()); }