/// <summary> /// The validate. /// </summary> /// <param name="validationContext"> /// The validation context. /// </param> /// <returns> /// The set of validation result. /// </returns> public override IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { if (Intervals != null && Intervals.Any()) { var currentDayStart = DateTime.Now.Date; var clientTime = DateTime.Now.TimeOfDay; var firstIntervalOfCurrentDay = Intervals.Where(t => t.AttendanceDate.Date == currentDayStart) .OrderBy(t => t.ClockIn) .FirstOrDefault(); if (firstIntervalOfCurrentDay != null && (clientTime - firstIntervalOfCurrentDay.ClockIn).TotalHours > TotalHoursLimit) { yield return(new ValidationResult(ValidationMessages.TotalHoursExceedLimit)); } } foreach (var baseError in base.Validate(validationContext)) { yield return(baseError); } }
public bool IsMatch(DayOfWeek day, TimeSpan span) { return(Intervals.Any(x => x.Day == day && x.OpenTime <= span && x.CloseTime >= span)); }