Пример #1
0
        public ActionResult DeleteWithRollBack(int id)
        {
            Transaction transaction = ServiceFactory.GetTransactionServices().Get(id);

            if (transaction.JournalId != 0)
            {
                ServiceFactory.GetJournalServices().Delete(transaction.JournalId);
            }

            IAccountServices           accService    = ServiceFactory.GetAccountServices();
            ITransactionTypeServices   tTypeService  = ServiceFactory.GetTransactionTypeServices();
            ITransactionDetailServices detailService = ServiceFactory.GetTransactionDetailServices();

            List <TransactionDetail> detail  = (List <TransactionDetail>)detailService.GetAll(transaction.Id);
            List <Account>           accList = new List <Account>();

            foreach (TransactionDetail d in detail)
            {
                Account         acc    = accService.Get(d.AccountId);
                TransactionType type   = tTypeService.Get(d.TransactionType);
                string          action = accService.GetRollBackAction(acc.Id, type.Type);

                if (action == "Increase")
                {
                    acc.Amount += d.Amount;
                }
                else
                {
                    acc.Amount -= d.Amount;
                }
                accService.Update(acc);
                accList.Add(acc);
                detailService.Delete(d.Id);
            }
            ServiceFactory.GetTransactionServices().Delete(transaction.Id);
            ViewBag.AccountList = accList;
            return(View());
        }
Пример #2
0
        public ActionResult DeleteWithoutRollBack(int id)
        {
            ITransactionServices       transactionService = ServiceFactory.GetTransactionServices();
            ITransactionDetailServices detailService      = ServiceFactory.GetTransactionDetailServices();

            Transaction t = transactionService.Get(id);

            if (t.JournalId != 0)
            {
                ServiceFactory.GetJournalServices().Delete(t.JournalId);
            }

            List <TransactionDetail> detail = (List <TransactionDetail>)detailService.GetAll(t.Id);
            List <int> accId = new List <int>();

            foreach (TransactionDetail d in detail)
            {
                accId.Add(d.AccountId);
                detailService.Delete(d.Id);
            }
            transactionService.Delete(t.Id);
            return(View(accId));
        }