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); }
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); }
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(); }
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(); }
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); }
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); }