예제 #1
0
        public void EditExpense(ExpenseDetails ExpenseDetails)
        {
            var Expense = _ExpenseRepository.GetById(ExpenseDetails.Id, true);

            var oldMovement = new Movement(Mapper.Map <ExpenseDetails>(Expense));

            Expense = Mapper.Map <Expense>(ExpenseDetails);
            if (Expense.GeneratedIncomeId.HasValue)
            {
                Expense.GeneratedIncomeId = (int?)null;
                _ExpenseRepository.Update(Expense);
            }

            var strategy    = ContextMovementStrategy.GetMovementStrategy(oldMovement, _bankAccountRepository, _historicMovementRepository, _incomeRepository, _atmWithdrawRepository);
            var newMovement = new Movement(ExpenseDetails);

            strategy.UpdateDebit(newMovement);

            if (newMovement.TargetIncomeId.HasValue)
            {
                // Update the GenerateIncomeId.
                Expense.GeneratedIncomeId = newMovement.TargetIncomeId.Value;
            }

            _ExpenseRepository.Update(Expense);
        }
예제 #2
0
        public void EditSaving(SavingDetails savingDetails)
        {
            var saving = _savingRepository.GetById(savingDetails.Id, true);

            var oldMovement = new Movement(Mapper.Map <SavingDetails>(saving));

            // Update the saving . Reset of generated income as it might be deleted when UpdateDebit.
            saving = Mapper.Map <Saving>(savingDetails);
            saving.GeneratedIncomeId = (int?)null;
            _savingRepository.Update(saving);

            var strategy    = ContextMovementStrategy.GetMovementStrategy(oldMovement, _bankAccountRepository, _historicMovementRepository, _incomeRepository, _atmWithdrawRepository);
            var newMovement = new Movement(savingDetails);

            strategy.UpdateDebit(newMovement);

            if (!newMovement.TargetIncomeId.HasValue)
            {
                throw new ArgumentException("Target Income ID should not be null.");
            }

            // Update the GenerateIncomeId.
            saving.GeneratedIncomeId = newMovement.TargetIncomeId.Value;
            _savingRepository.Update(saving);
        }
예제 #3
0
        public void DeleteExpense(int id)
        {
            var Expense        = _ExpenseRepository.GetById(id);
            var ExpenseDetails = Mapper.Map <ExpenseDetails>(Expense);

            _ExpenseRepository.Delete(Expense);

            var strategy = ContextMovementStrategy.GetMovementStrategy(new Movement(ExpenseDetails), _bankAccountRepository, _historicMovementRepository, _incomeRepository, _atmWithdrawRepository);

            strategy.Credit();
        }
예제 #4
0
        public void DeleteSaving(int id)
        {
            var saving        = _savingRepository.GetById(id);
            var savingDetails = Mapper.Map <SavingDetails>(saving);

            _savingRepository.Delete(saving);

            var strategy = ContextMovementStrategy.GetMovementStrategy(new Movement(savingDetails), _bankAccountRepository, _historicMovementRepository, _incomeRepository, _atmWithdrawRepository);

            strategy.Credit();
        }
예제 #5
0
        public void CreateExpense(ExpenseDetails expenseDetails)
        {
            var Expense = Mapper.Map <Expense>(expenseDetails);

            var movement = new Movement(expenseDetails);

            var strategy = ContextMovementStrategy.GetMovementStrategy(movement, _bankAccountRepository, _historicMovementRepository, _incomeRepository, _atmWithdrawRepository);

            strategy.Debit();

            if (movement.TargetIncomeId.HasValue)
            {
                Expense.GeneratedIncomeId = movement.TargetIncomeId.Value;
            }

            _ExpenseRepository.Create(Expense);
        }
예제 #6
0
        public void CreateSaving(SavingDetails savingDetails)
        {
            var saving = Mapper.Map <Saving>(savingDetails);

            var movement = new Movement(savingDetails);

            var strategy = ContextMovementStrategy.GetMovementStrategy(movement, _bankAccountRepository, _historicMovementRepository, _incomeRepository, _atmWithdrawRepository);

            strategy.Debit();

            if (!movement.TargetIncomeId.HasValue)
            {
                throw new ArgumentException("Target Income ID should not be null.");
            }

            saving.GeneratedIncomeId = movement.TargetIncomeId.Value;

            _savingRepository.Create(saving);
        }