Skip to content

Instantly share code, notes, and snippets.

@milannankov
Created December 24, 2018 07:50
Show Gist options
  • Save milannankov/b139832aa7ca717b260586a7b15637e0 to your computer and use it in GitHub Desktop.
Save milannankov/b139832aa7ca717b260586a7b15637e0 to your computer and use it in GitHub Desktop.
domain-models-2
public class BankAccount
{
public string Id { get; }
public Money Balance { get; private set; }
public BankAccount(string id, Money balance)
{
if(string.IsNullOrEmpty(id))
{
throw new ArgumentNullException(nameof(id));
}
this.Id = id;
this.Balance = balance;
}
public void Deposit(Money depositAmount)
{
if(!this.Balance.HasSameCurrency(depositAmount))
{
throw new InvalidOperationException("Cannot deposit using different currency.")
}
this.Balance = this.Balance.Add(depositAmount);
}
public void Debit(Money debitAmount)
{
if (!this.Balance.HasSameCurrency(debitAmount))
{
throw new InvalidOperationException("Cannot debit using different currency.");
}
this.Balance = this.Balance.Subtract(debitAmount);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment