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 Movement(SavingDetails saving) { this.Date = saving.DateSaving; this.Description = saving.Description; this.Amount = saving.Amount; this.PaymentMethod = PaymentMethod.InternalTransfer; this.SourceAccountId = saving.AccountId; this.TargetAccountId = saving.TargetInternalAccountId; this.TargetIncomeId = saving.GeneratedIncomeId; }
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); }
public void Put(int id, [FromBody] SavingDetails editedObj) { _SavingService.EditSaving(editedObj); }
public void Post([FromBody] SavingDetails createdObj) { _SavingService.CreateSaving(createdObj); }