I'm working on a system where users have different types of 'Accounts' of the financial type. I'm struggling to come up with a design that works.
Background
A user has 2 types of accounts: A 'tab' account and a 'debt' account.
Debt
Here, the 'head office' pays for things for the user. Things like an event, a dinner,.. At some point the user adds money to the account to set the balance back to zero. I have no problem modelling this, as it are merely transactions
Tab
This account holds transactions related to orders the user has placed. A user, for example, orders 2 drinks from the bar. The cost of this, I think, should also be modelled as a transaction with a reference to the order that generated the transaction.
Here, the account also has a balance. Specific to the orders
Right now I've modelled it like this.
public abstract class Account
{
public Guid Id { get; set; }
public decimal Balance { get; set; }
public DateTime LastUpdated { get; set; }
}
public class DebtAccount: Account
{
public ICollection<DebtTransaction> Transactions { get; set; }
}
public class TabAccount: Account
{
public ICollection<TabTransaction> Transactions { get; set; }
}
public abstract class Transaction
{
public Guid Id { get; set; }
public decimal Amount { get; set; }
public DateTime Date { get; set; }
public string Description { get; set; }
}
public class TabTransaction : Transaction
{
public Orderline Consumption { get; set; }
}
public class DebtTransaction : Transaction
{
}
public class User {
public DebtAccount DebtAccount {get;set;}
public TabAccount TabAccount {get;set;}
}
I keep looking at it, thinking something doesn't feel right, but I can't come up with a better solution.
I'm also struggling with how to translate it to a database design.
Extra information: I'm writing the application in C#, .NET and Entity Framework.
All advice, small or big would be much appreciated.