Пример #1
0
        private void ExecuteDeleteExpense()
        {
            MessageBoxResult result = MessageBox.Show("Deleting Expense will delete all of the details also, \nAre you sure to delete", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                if (CurrentExpense != null)
                {
                    using (var unitofWork = new UnitOfWork(new MahalluDBContext())) {
                        MahalluManager.Model.Expense expense = unitofWork.Expenses.Get(CurrentExpense.Id);
                        unitofWork.Expenses.Remove(expense);
                        unitofWork.Complete();

                        ExpenseType totatExpenseType = new ExpenseType()
                        {
                            Expense = CurrentExpense, Operation = MahalluManager.Model.Common.Operation.Delete
                        };
                        eventAggregator.GetEvent <PubSubEvent <ExpenseType> >().Publish(totatExpenseType);

                        ExpenseList.Remove(CurrentExpense);
                        CurrentExpense = null;
                    }
                }
            }
        }
Пример #2
0
        public SummaryViewModel()
        {
            eventAggregator.GetEvent <PubSubEvent <SelectedYearType> >().Subscribe((e) => {
                Selected = ((SelectedYearType)e).SelectedYear;
            });
            eventAggregator.GetEvent <PubSubEvent <IncomeType> >().Subscribe((e) => {
                IncomeType incomeType = (IncomeType)e;

                bool isPresent    = false;
                Contribution temp = null;
                foreach (var item in ContributionList)
                {
                    if (item.Id == incomeType.Contribution.Id)
                    {
                        item.ToatalAmount = incomeType.Contribution.ToatalAmount;
                        isPresent         = true;
                        if (incomeType.Operation == MahalluManager.Model.Common.Operation.Delete)
                        {
                            temp = item;
                            break;
                        }
                    }
                }
                if (temp != null)
                {
                    contributionList.Remove(temp);
                }
                if (!isPresent)
                {
                    ContributionList.Add(incomeType.Contribution);
                }
                TotalIncome = CalcuateTotalIncome();
            });

            eventAggregator.GetEvent <PubSubEvent <ExpenseType> >().Subscribe((e) => {
                ExpenseType expenseType = (ExpenseType)e;
                bool isPresent          = false;
                Expense temp            = null;
                foreach (var item in ExpenseList)
                {
                    if (item.Id == expenseType.Expense.Id)
                    {
                        item.ToatalAmount = expenseType.Expense.ToatalAmount;
                        isPresent         = true;
                        if (expenseType.Operation == MahalluManager.Model.Common.Operation.Delete)
                        {
                            temp = item;
                            break;
                        }
                    }
                }
                if (temp != null)
                {
                    ExpenseList.Remove(temp);
                }
                if (!isPresent)
                {
                    ExpenseList.Add(expenseType.Expense);
                }
                TotalExpense = CalcuateTotalExpense();
            });
            Refresh();
            Years = new ObservableCollection <string>();
            SetYears();
        }