Updated ef migrations.
This commit is contained in:
@@ -8,8 +8,20 @@ public enum AccountType
|
||||
Revenue
|
||||
}
|
||||
|
||||
public record Account(int Id, decimal Balance, AccountType Type)
|
||||
public record Account
|
||||
{
|
||||
public Account(int Id, decimal Balance, AccountType Type)
|
||||
{
|
||||
this.Id = Id;
|
||||
this.Balance = Balance;
|
||||
this.Type = Type;
|
||||
|
||||
if (Balance < 0 && Type is AccountType.Liability or AccountType.Debit or AccountType.Revenue)
|
||||
{
|
||||
throw new InvalidStartingBalanceException("Insufficient funds.");
|
||||
}
|
||||
}
|
||||
|
||||
public Account ApplyPosting(decimal amount, EntryType entryType)
|
||||
{
|
||||
if (amount <= 0)
|
||||
@@ -18,7 +30,6 @@ public record Account(int Id, decimal Balance, AccountType Type)
|
||||
}
|
||||
|
||||
var newBalance = entryType == EntryType.Credit ? Balance + amount : Balance - amount;
|
||||
;
|
||||
|
||||
if (newBalance < 0 && Type is AccountType.Liability or AccountType.Debit or AccountType.Revenue)
|
||||
{
|
||||
@@ -27,6 +38,15 @@ public record Account(int Id, decimal Balance, AccountType Type)
|
||||
|
||||
return this with { Balance = newBalance };
|
||||
}
|
||||
}
|
||||
|
||||
public class InsufficientFundsException(string insufficientFunds) : Exception(insufficientFunds);
|
||||
public int Id { get; init; }
|
||||
public decimal Balance { get; init; }
|
||||
public AccountType Type { get; init; }
|
||||
|
||||
public void Deconstruct(out int Id, out decimal Balance, out AccountType Type)
|
||||
{
|
||||
Id = this.Id;
|
||||
Balance = this.Balance;
|
||||
Type = this.Type;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user