public void UpdateExpenseTest()
 {
     CommonTestObjects.RecreateAll();
     PersonViewModel person1 = Application.GetPerson(Database.User1Id);
     Assert.IsNotNull(person1);
     AccountViewModel account = person1.UserAccounts.First();
     long amount = 100;
     ExpenseViewModel expense = new ExpenseViewModel(new Expense(0, account.AccountId, amount, Database.CatFoodId, DateTime.Now, string.Empty), Application);
     long expenseId = Application.AddExpense(expense);
     AccountBalance accState = account.GetState();
     long oldBalance = accState.balance;
     expense.Amount = 150;
     Application.UpdateExpense(expense);
     accState = account.GetState();
     long newBalance = accState.balance;
     Assert.AreEqual(newBalance + 50, oldBalance);
     PersonViewModel person2 = Application.GetPerson(Database.User2Id);
     AccountViewModel account2 = person2.UserAccounts.First();
     AccountBalance accState2 = account2.GetState();
     long accBalance2 = accState2.balance;
     expense.Account = account2;
     Application.UpdateExpense(expense);
     accState = account.GetState();
     accState2 = account2.GetState();
     newBalance = accState.balance;
     Assert.AreEqual(newBalance, 0);
     Assert.AreEqual(accState2.balance + 150, accBalance2);
 }
 public void DeleteExpenseTest()
 {
     PersonViewModel person1 = Application.GetPerson(Database.User1Id);
     Assert.IsNotNull(person1);
     AccountViewModel account = person1.UserAccounts.First();
     Assert.IsNotNull(account);
     AccountBalance accState = account.GetState();
     long oldBalance = accState.balance;
     long amount = 100;
     ExpenseViewModel expense = new ExpenseViewModel(new Expense(0, account.AccountId, amount, Database.CatFoodId, DateTime.Now, string.Empty), Application);
     Application.AddExpense(expense);
     accState = account.GetState();
     long newBalance = accState.balance;
     Assert.AreEqual(oldBalance - amount, newBalance);
     Application.DeleteExpense(expense);
     accState = account.GetState();
     newBalance = accState.balance;
     Assert.AreEqual(oldBalance, newBalance);
 }
 public void DeleteExpense(ExpenseViewModel expense)
 {
     m_database.DeleteExpense(expense.UnderlyingData);
     Expenses.Remove(expense);
     expense.Account.UpdateAccountState();
     if (null != SelectedReport)
         SelectedReport.RefreshView();
 }
 public void UpdateExpense(ExpenseViewModel expense)
 {
     AccountViewModel oldAccount = null;
     if (expense.Account.AccountId != expense.AccountId)
         oldAccount = GetAccount(expense.AccountId);
     expense.UpdateUnderlyingData();
     m_database.UpdateExpense(expense.UnderlyingData);
     expense.Account.UpdateAccountState();
     if (null != oldAccount)
         oldAccount.UpdateAccountState();
     if (null != SelectedReport)
         SelectedReport.RefreshView();
 }
 public long AddExpense(ExpenseViewModel expense)
 {
     Expense refExpense = expense.UnderlyingData;
     m_database.AddExpense(ref refExpense);
     expense.UnderlyingData = refExpense;
     Expenses.Add(expense);
     expense.Account.UpdateAccountState();
     if (null != SelectedReport)
         SelectedReport.RefreshView();
     return refExpense.expenseId;
 }