Last active
August 26, 2018 21:36
-
-
Save Theoistic/cc4587db4ae9684ff3943749350e052a to your computer and use it in GitHub Desktop.
Booking Sketch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static List<TimeSlot> GetAvailableTimeSlots(this ServiceEntry service, DateTime start, DateTime end, TimeSpan duration, Func<ResourceEntry, bool> resourcePredicate) | |
{ | |
var Unavailable = service.Bookings.Where(x => resourcePredicate(x.Resource)).Select(y => y.Period); | |
List<TimeSlot> OriginalAvail = new List<TimeSlot>(); | |
DateTime setTime = start; | |
while (setTime < end) | |
{ | |
if ((setTime.Hour < start.Hour) || (setTime.Hour > end.Hour)) | |
{ | |
setTime = setTime.Add(duration); | |
continue; | |
} | |
TimeSlot foundEntry = Unavailable.FirstOrDefault(x => x.Start <= setTime && x.End >= (setTime.Add(duration))); | |
OriginalAvail.Add(new TimeSlot | |
{ | |
Start = setTime, | |
End = setTime.Add(duration), | |
IsFree = foundEntry == null, | |
Description = foundEntry != null ? foundEntry.Description : "", | |
}); | |
setTime = setTime.Add(duration); | |
} | |
return OriginalAvail; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment