diff --git a/Billing.Shared/Views/AccountPage.xaml.cs b/Billing.Shared/Views/AccountPage.xaml.cs index 20054a9..d0f53ef 100644 --- a/Billing.Shared/Views/AccountPage.xaml.cs +++ b/Billing.Shared/Views/AccountPage.xaml.cs @@ -43,23 +43,22 @@ namespace Billing.Views accounts.Clear(); foreach (var account in App.Accounts) { - account.Balance = account.Initial + App.Bills.Where(b => b.WalletId == account.Id).Sum(b => b.Amount); AddToAccountGroup(account); } } - else + groupLayout.Refresh(accounts); + RefreshBalance(true); + } + + private void RefreshBalance(bool calc = false) + { + if (calc) { foreach (var account in App.Accounts) { account.Balance = account.Initial + App.Bills.Where(b => b.WalletId == account.Id).Sum(b => b.Amount); } - } - groupLayout.Refresh(accounts); - RefreshBalance(); - } - - private void RefreshBalance() - { + } SetValue(BalanceProperty, App.Accounts.Sum(a => a.Balance)); } @@ -139,13 +138,14 @@ namespace Billing.Views private void AccountChecked(object sender, AccountEventArgs e) { - if (e.Account.Id < 0) + var add = e.Account.Id < 0; + if (add) { App.Accounts.Add(e.Account); AddToAccountGroup(e.Account); } groupLayout.Refresh(accounts); - RefreshBalance(); + RefreshBalance(!add); Task.Run(App.WriteAccounts); }