public void SaveBudgets(ObservableCollection<Budget> budgets, Action<Exception> callback) { App.Instance.StaticServiceData.SetServerStatus(async status => { //continue with local if status is ok but is pending Sync if (status != Model.StaticServiceData.ServerStatus.Ok || !App.Instance.IsSync) { try { foreach (var item in BudgetList.Where(x => x.HasChanges)) item.HasChanges = false; await SetupBudgetList(budgets, false); App.Instance.IsSync = false; callback(null); } catch (Exception ex) { callback(ex); } } else { var client = new MainClient(); client.SaveBudgetsAsync(budgets); client.SaveBudgetsCompleted += async (sender, completedEventArgs) => { if (completedEventArgs.Error == null) { await SetupBudgetList(completedEventArgs.Result, true); //Only update sync when offline and in login and main pages //App.Instance.IsSync = true; callback(null); } else callback(completedEventArgs.Error); }; } }); }