Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Method 1:
- public async Task<int?> GetQueuePositionAsync(User user, Book book)
- {
- var bookRservations = await context.Reservations
- .Where(r => r.BookID == book.ID)
- .OrderBy(r => r.CreatedOn).ToListAsync();
- var position = bookRservations.FindIndex(r => r.UserID == user.Id);
- return ++position;
- }
- Method 2:
- public async Task<bool> IsUserFirstToCheckOutAsync(string userId, int bookId)
- {
- var isBookReservedByUser = await IsBookReservedByUserAsync(bookId, userId);
- if (isBookReservedByUser)
- {
- var reservations = await GetReservationsByBookIdAsync(bookId);
- var userFirstInQueue = reservations.OrderBy(x => x.CreatedOn).First();
- var isCurrentUserFirst = userFirstInQueue.UserID == userId;
- return isCurrentUserFirst;
- }
- else return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement