Exemplo n.º 1
0
        private void OnAddNewExpenseExecute(ExpenseBucket expense)
        {
            Dirty = true;
            var newExpense = Expenses.AddNew();

            Debug.Assert(newExpense != null);
            newExpense.Amount = 0;

            // New buckets must be created because the one passed in, is a single command parameter instance to be used as a type indicator only.
            // If it was used, the same instance would overwritten each time an expense is created.
            if (expense is SpentMonthlyExpenseBucket)
            {
                newExpense.Bucket = new SpentMonthlyExpenseBucket(string.Empty, string.Empty);
            }
            else if (expense is SavedUpForExpenseBucket)
            {
                newExpense.Bucket = new SavedUpForExpenseBucket(string.Empty, string.Empty);
            }
            else if (expense is SavingsCommitmentBucket)
            {
                newExpense.Bucket = new SavingsCommitmentBucket(string.Empty, string.Empty);
            }
            else
            {
                throw new InvalidCastException("Invalid type passed to Add New Expense: " + expense);
            }

            Expenses.RaiseListChangedEvents = true;
            newExpense.PropertyChanged     += OnExpenseAmountPropertyChanged;
        }