-
-
Save Pownraj-2818/7433000d49aca790b3249db66115a6fb to your computer and use it in GitHub Desktop.
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
private async Task<bool> IsSpaceAvailable(int spaceId, DateTime startTime, DateTime endTime) | |
{ | |
var reservationList = await _context.Reservations | |
.Where(reservation => | |
reservation.ReservedSpaceId == spaceId && | |
!reservation.IsDeleted && | |
!reservation.IsCancelled | |
) | |
.ToListAsync(); | |
// 4 Edge cases | |
foreach (var reservation in reservationList) | |
{ | |
if (endTime > reservation.StartsAt && endTime < reservation.EndsAt) | |
return false; | |
if (startTime <= reservation.StartsAt && endTime >= reservation.EndsAt) | |
return false; | |
if (startTime > reservation.StartsAt && startTime <= reservation.EndsAt) | |
return false; | |
if (startTime > reservation.StartsAt && endTime < reservation.EndsAt) | |
return false; | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment