public AccountDTO getAccountById(int accountId) { Account account = accountRepository.GetByID(accountId); if (account == null) { throw new InvalidOperationException("No account found with that accountId"); } return(AccountConverter.toDto(account)); }
public AccountDTO updateAccount(int accountId, AccountDTO accountDto) { Account account = accountRepository.GetByID(accountId); if (account == null) { throw new InvalidOperationException("No account found with that id"); } account.Amount = accountDto.Amount; accountRepository.Update(account); return(AccountConverter.toDto(account)); }
public AccountDTO createAccount(AccountDTO accountDto) { if (accountDto.Amount < 0) { throw new InvalidOperationException("Impossible to have a negative balance"); } Account account = new Account { Client = null, CreationDate = DateTime.Now, Amount = accountDto.Amount, Id = accountDto.Id, Type = accountDto.Type }; accountRepository.Insert(account); return(AccountConverter.toDto(account)); }