Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. Method 1:
  2. public async Task<int?> GetQueuePositionAsync(User user, Book book)
  3. {
  4. var bookRservations = await context.Reservations
  5. .Where(r => r.BookID == book.ID)
  6. .OrderBy(r => r.CreatedOn).ToListAsync();
  7. var position = bookRservations.FindIndex(r => r.UserID == user.Id);
  8. return ++position;
  9. }
  10.  
  11. Method 2:
  12. public async Task<bool> IsUserFirstToCheckOutAsync(string userId, int bookId)
  13. {
  14. var isBookReservedByUser = await IsBookReservedByUserAsync(bookId, userId);
  15. if (isBookReservedByUser)
  16. {
  17. var reservations = await GetReservationsByBookIdAsync(bookId);
  18. var userFirstInQueue = reservations.OrderBy(x => x.CreatedOn).First();
  19. var isCurrentUserFirst = userFirstInQueue.UserID == userId;
  20. return isCurrentUserFirst;
  21. }
  22. else return false;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement