Skip to content

Instantly share code, notes, and snippets.

@dcomartin
Created October 22, 2025 15:16
Show Gist options
  • Select an option

  • Save dcomartin/4c271c8b0b48078f7bcae5e9b9cacae6 to your computer and use it in GitHub Desktop.

Select an option

Save dcomartin/4c271c8b0b48078f7bcae5e9b9cacae6 to your computer and use it in GitHub Desktop.
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