-
-
Save dcomartin/4c271c8b0b48078f7bcae5e9b9cacae6 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, Guid currentUserId) | |
| { | |
| if (currentUserId != OwnerUserId) | |
| { | |
| throw new UnauthorizedAccessException("You are not allowed to withdraw from this account."); | |
| } | |
| if (amount > Balance) | |
| { | |
| throw new InvalidOperationException("Insufficient funds."); | |
| } | |
| Balance -= amount; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment