public async Task ClearEventAsync(string eventId, CancellationToken cancellationToken) { var eventsDictionary = await stateManager.GetAllReliableEventsAsync(); using (var transaction = stateManager.CreateTransaction()) { await eventsDictionary.TryRemoveAsync(transaction, eventId); await transaction.CommitAsync(); } }
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(); } }