private async void LoadNewDraft() { if (currentUserId == null) { return; } var userId = currentUserId.Value; // Load data: var draftModel = await TimeEntryModel.GetDraftAsync(); // Check that the user hasn't changed in the mean time if (userId != currentUserId) { return; } // Update data if (draftModel != null) { var draftData = draftModel.Data; if (!draftEntries.UpdateData(draftData)) { draftEntries.Add(draftData); } } UpdateProperties(); }
private async void LoadTimeEntries() { if (currentUserId == null) { return; } var userId = currentUserId.Value; var store = ServiceContainer.Resolve <IDataStore> (); // Load data: var draftTask = TimeEntryModel.GetDraftAsync(); var runningTask = store.Table <TimeEntryData> () .QueryAsync(r => r.State == TimeEntryState.Running && r.DeletedAt == null && r.UserId == userId); await Task.WhenAll(draftTask, runningTask); // Check that the user hasn't changed in the mean time if (userId != currentUserId) { return; } // Update data var draftModel = draftTask.Result; if (draftModel != null) { var draftData = draftModel.Data; if (!draftEntries.UpdateData(draftData)) { draftEntries.Add(draftData); } } foreach (var entry in runningTask.Result) { if (!runningEntries.UpdateData(entry)) { runningEntries.Add(entry); } } UpdateProperties(); TryEnforceSingleRunning(); }