Skip to content

Instantly share code, notes, and snippets.

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

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

Select an option

Save dcomartin/b962e2a9f0149de8e8ab9b9a09cac02c 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)
{
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