コード例 #1
0
        private void ExecueDeleteExpenseDetail()
        {
            MessageBoxResult result = MessageBox.Show("Are you sure to delete " + CurrentExpenseDetail.Name, "Delete", MessageBoxButton.YesNo, MessageBoxImage.Warning);

            if (result == MessageBoxResult.Yes)
            {
                if (CurrentExpenseDetail != null)
                {
                    using (var unitOfWork = new UnitOfWork(new MahalluDBContext())) {
                        ExpenseDetails expenseDetail = unitOfWork.ExpenseDetails.Get(CurrentExpenseDetail.Id);
                        if (expenseDetail != null)
                        {
                            unitOfWork.ExpenseDetails.Remove(expenseDetail);
                            unitOfWork.Complete();

                            decimal amount = CurrentExpenseDetail.Amount;
                            ExpenseDetailList.Remove(CurrentExpenseDetail);
                            CurrentExpenseDetail = null;

                            //To update total amount
                            CurrentExpense.ToatalAmount = Convert.ToDecimal(TotalAmount) - amount;
                            TotalAmount = (Convert.ToDecimal(TotalAmount) - amount).ToString();
                            //TotalExpense = -amount;
                            unitOfWork.Expenses.Update(CurrentExpense);
                            unitOfWork.Complete();

                            ExpenseType totatExpenseType = new ExpenseType()
                            {
                                Expense = CurrentExpense
                            };
                            eventAggregator.GetEvent <PubSubEvent <ExpenseType> >().Publish(totatExpenseType);
                        }
                    }
                }
            }
        }