Exemple #1
0
        void ExecuteDeleteIncomeCommand(object item)
        {
            if (IsBusy)
            {
                return;
            }

            IsBusy = true;
            Income itemAsIncome = (Income)item;

            try
            {
                var income = Incomes.FirstOrDefault(x => x.Id == itemAsIncome.Id);
                DataStore.Delete(income);
                Incomes.Remove(income);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            finally
            {
                IsBusy = false;
            }
        }
        private void OnDeleteBudgetItemCommandExecute(object budgetItem)
        {
            bool?response = this.questionBox.Show(
                "Are you sure you want to delete this budget bucket?\nAnalysis may not work correctly if transactions are allocated to this bucket.",
                "Delete Budget Bucket");

            if (response == null || response.Value == false)
            {
                return;
            }

            Dirty = true;
            var expenseItem = budgetItem as Expense;

            if (expenseItem != null)
            {
                expenseItem.PropertyChanged        -= OnExpenseAmountPropertyChanged;
                expenseItem.Bucket.PropertyChanged -= OnExpenseAmountPropertyChanged;
                Expenses.Remove(expenseItem);
                return;
            }

            var incomeItem = budgetItem as Income;

            if (incomeItem != null)
            {
                incomeItem.PropertyChanged        -= OnIncomeAmountPropertyChanged;
                incomeItem.Bucket.PropertyChanged -= OnIncomeAmountPropertyChanged;
                Incomes.Remove(incomeItem);
            }
        }
Exemple #3
0
        protected override void When(object @event)
        {
            Income      income;
            Outgo       outgo;
            Snapshot    snapshot;
            Expenditure expenditure;

            switch (@event)
            {
            case Events.DailyBudgetCreated e:
                Id       = new DailyBudgetId(e.Id);
                Name     = new BudgetName(e.Name);
                snapshot = new Snapshot(Apply);
                ApplyToEntity(snapshot, e);
                Snapshot = snapshot;
                break;

            case Events.IncomeAddedToDailyBudget e:
                income = new Income(Apply);
                ApplyToEntity(income, e);
                Incomes.Add(income);
                e.TotalIncome = TotalIncome();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.IncomeAmountChanged e:
                income = Incomes.FirstOrDefault(i => i.Id == e.IncomeId);
                if (income == null)
                {
                    throw new InvalidOperationException($"Income with id {e.IncomeId} not found");
                }
                ApplyToEntity(income, e);
                e.TotalIncome = TotalIncome();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.IncomeDescriptionChanged e:
                income = Incomes.FirstOrDefault(i => i.Id == e.IncomeId);
                if (income == null)
                {
                    throw new InvalidOperationException($"Income with id {e.IncomeId} not found");
                }
                ApplyToEntity(income, e);
                break;

            case Events.IncomeRemoved e:
                income = Incomes.FirstOrDefault(i => i.Id == e.IncomeId);
                if (income == null)
                {
                    throw new InvalidOperationException($"Income with id {e.IncomeId} not found");
                }
                Incomes.Remove(income);
                e.TotalIncome = TotalIncome();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.OutgoAddedToDailyBudget e:
                outgo = new Outgo(Apply);
                ApplyToEntity(outgo, e);
                Outgos.Add(outgo);
                e.TotalOutgo = TotalOutgo();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.OutgoAmountChanged e:
                outgo = Outgos.FirstOrDefault(i => i.Id == e.OutgoId);
                if (outgo == null)
                {
                    throw new InvalidOperationException($"Outgo with id {e.OutgoId} not found");
                }
                ApplyToEntity(outgo, e);
                e.TotalOutgo = TotalOutgo();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.OutgoDescriptionChanged e:
                outgo = Outgos.FirstOrDefault(i => i.Id == e.OutgoId);
                if (outgo == null)
                {
                    throw new InvalidOperationException($"Outgo with id {e.OutgoId} not found");
                }
                ApplyToEntity(outgo, e);
                break;

            case Events.OutgoRemoved e:
                outgo = Outgos.FirstOrDefault(o => o.Id == e.OutgoId);
                if (outgo == null)
                {
                    throw new InvalidOperationException($"Outgo with id {e.OutgoId} not found");
                }
                Outgos.Remove(outgo);
                e.TotalOutgo = TotalOutgo();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.ExpenditureAdded e:
                expenditure = new Expenditure(Apply);
                ApplyToEntity(expenditure, e);
                Expenditures.Add(expenditure);
                e.TotalExpenditure = TotalExpenditure();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.ExpenditureAmountChanged e:
                expenditure = Expenditures.FirstOrDefault(exp => exp.Id == e.ExpenditureId);
                if (expenditure == null)
                {
                    throw new InvalidOperationException($"Expenditure with id {e.ExpenditureId} not found");
                }
                ApplyToEntity(expenditure, e);
                e.TotalExpenditure = TotalExpenditure();
                ApplyToEntity(Snapshot, e);
                break;

            case Events.PeriodAddedToDailyBudget e:
                if (Period != null)
                {
                    throw new InvalidOperationException($"Period has already been set. Update start or end");
                }
                Period = Period.Create(e.Start, e.End);
                ApplyToEntity(Snapshot, e);
                break;

            case Events.PeriodStartChanged e:
                Period = Period.Create(e.Start, Period.ToB);
                ApplyToEntity(Snapshot, e);
                break;

            case Events.PeriodEndChanged e:
                Period = Period.Create(Period.FromA, e.End);
                ApplyToEntity(Snapshot, e);
                break;
            }
        }