Created
July 22, 2018 07:41
-
-
Save ivanpaulovich/d8050e2bc3d02a8fcca011d6d17f4831 to your computer and use it in GitHub Desktop.
DepositUseCase.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public sealed class DepositUseCase : IDepositUseCase | |
{ | |
private readonly IAccountReadOnlyRepository _accountReadOnlyRepository; | |
private readonly IAccountWriteOnlyRepository _accountWriteOnlyRepository; | |
public DepositUseCase( | |
IAccountReadOnlyRepository accountReadOnlyRepository, | |
IAccountWriteOnlyRepository accountWriteOnlyRepository) | |
{ | |
_accountReadOnlyRepository = accountReadOnlyRepository; | |
_accountWriteOnlyRepository = accountWriteOnlyRepository; | |
} | |
public async Task<DepositOutput> Execute(Guid accountId, Amount amount) | |
{ | |
Account account = await _accountReadOnlyRepository.Get(accountId); | |
if (account == null) | |
throw new AccountNotFoundException($"The account {accountId} does not exists or is already closed."); | |
account.Deposit(amount); | |
Credit credit = (Credit)account.GetLastTransaction(); | |
await _accountWriteOnlyRepository.Update( | |
account, | |
credit); | |
DepositOutput output = new DepositOutput( | |
credit, | |
account.GetCurrentBalance()); | |
return output; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment