public async Task <IEnumerable <BookingRepresentation> > ListPendingAsync(string user) { ConditionalValue <List <BookingRecord> > result; var dictionary = await stateManager.GetUserBookingsAsync(); using (var transaction = stateManager.CreateTransaction()) { result = await dictionary.TryGetValueAsync(transaction, user); await transaction.CommitAsync(); } return(result.HasValue ? result.Value.Where(booking => booking.CanceledOn == null && booking.CheckedInOn == null).Select(booking => booking.ToRepresentation()).ToList() : new List <BookingRepresentation>()); }
public async Task SaveChangesAsync() { var bookingsDictionary = await stateManager.GetAllBookingsAsync(); var userBookingsDictionary = await stateManager.GetUserBookingsAsync(); var eventsDictionary = addedEvents.Any() ? await stateManager.GetAllReliableEventsAsync() : null; using (var transaction = stateManager.CreateTransaction()) { foreach (var addedRecord in addedRecords) { await bookingsDictionary.AddAsync(transaction, addedRecord.Id, addedRecord); var userBookings = await userBookingsDictionary.GetOrAddAsync(transaction, addedRecord.User, new List <Models.BookingRecord>()); userBookings.Add(addedRecord); await userBookingsDictionary.SetAsync(transaction, addedRecord.User, userBookings); } foreach (var updatedRecord in updatedRecords) { await bookingsDictionary.SetAsync(transaction, updatedRecord.Id, updatedRecord); var userBookings = (await userBookingsDictionary.TryGetValueAsync(transaction, updatedRecord.User, LockMode.Update)).Value; var existingBooking = userBookings.First(b => b.Id == updatedRecord.Id); userBookings.Remove(existingBooking); userBookings.Add(updatedRecord); await userBookingsDictionary.SetAsync(transaction, updatedRecord.User, userBookings); } foreach (var addedEvent in addedEvents) { await eventsDictionary.AddAsync(transaction, addedEvent.Id, addedEvent); } await transaction.CommitAsync(); } }