Skip to content

Instantly share code, notes, and snippets.

@ivanpaulovich
Created July 22, 2018 07:41
Show Gist options
  • Save ivanpaulovich/d8050e2bc3d02a8fcca011d6d17f4831 to your computer and use it in GitHub Desktop.
Save ivanpaulovich/d8050e2bc3d02a8fcca011d6d17f4831 to your computer and use it in GitHub Desktop.
DepositUseCase.cs
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