-
-
Save dcomartin/b962e2a9f0149de8e8ab9b9a09cac02c to your computer and use it in GitHub Desktop.
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 class BankAccount | |
| { | |
| public Guid OwnerUserId { get; private set; } | |
| public decimal Balance { get; private set; } | |
| public BankAccount(Guid ownerUserId, decimal initialBalance) | |
| { | |
| OwnerUserId = ownerUserId; | |
| Balance = initialBalance; | |
| } | |
| public void Withdraw(decimal amount) | |
| { | |
| if (amount > Balance) | |
| { | |
| throw new InvalidOperationException("Insufficient funds."); | |
| } | |
| Balance -= amount; | |
| } | |
| } | |
| public class BankAccountService | |
| { | |
| public void WithdrawFromAccount(BankAccount account, decimal amount, Guid currentUserId) | |
| { | |
| if (currentUserId != account.OwnerUserId) | |
| { | |
| throw new UnauthorizedAccessException("You are not allowed to withdraw from this account."); | |
| } | |
| account.Withdraw(amount); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment