public async void BookFromQueue() { while (_db.Queues.Any() && _db.Computers.Any(c => !c.IsTaken && !c.IsBooked)) { var queue = _db.Queues.Include(q => q.User).First(q => q.Index == _db.Queues.Min(qu => qu.Index)); await _computerRepository.Book(1, queue.PreferredRoom, queue.User.Id); _db.Queues.Remove(queue); _db.SaveChanges(); } }
public async Task <IActionResult> Book(BookingViewModel bookingViewModel) { var user = await _userManager.FindByIdAsync(_currentUserId); var amountBooked = await _computerRepository.Book(bookingViewModel.AmountOfPlaces, bookingViewModel.Room, _currentUserId); if (amountBooked < bookingViewModel.AmountOfPlaces) { _queueRepository.PutInQueue(user, bookingViewModel.Room, bookingViewModel.AmountOfPlaces - amountBooked); } return(RedirectToAction("Index", "Home")); }