Add project files.

This commit is contained in:
rossmill76 committed 2026-03-01 18:17:42 +00:00
1 parent fd9f318d6a
commit 0ce077ec11
98 files changed
+65707

No files matched your search

+59
View File
@@ -0,0 +1,59 @@
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
namespace BudgetApp.Data;
public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
public DbSet<Account> Accounts => Set<Account>();
public DbSet<Transaction> Transactions => Set<Transaction>();
public DbSet<Category> Categories => Set<Category>();
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
builder.Entity<Account>(e =>
{
e.HasOne(a => a.User)
.WithMany()
.HasForeignKey(a => a.UserId)
.OnDelete(DeleteBehavior.Cascade);
e.Property(a => a.CurrentBalance).HasColumnType("decimal(18,2)");
});
builder.Entity<Transaction>(e =>
{
e.HasOne(t => t.Account)
.WithMany(a => a.Transactions)
.HasForeignKey(t => t.AccountId)
.OnDelete(DeleteBehavior.Cascade);
e.HasOne(t => t.Category)
.WithMany(c => c.Transactions)
.HasForeignKey(t => t.CategoryId)
.OnDelete(DeleteBehavior.SetNull);
e.HasOne(t => t.ParentTransaction)
.WithMany()
.HasForeignKey(t => t.ParentTransactionId)
.OnDelete(DeleteBehavior.SetNull);
e.Property(t => t.Amount).HasColumnType("decimal(18,2)");
});
builder.Entity<Category>(e =>
{
e.HasOne(c => c.User)
.WithMany()
.HasForeignKey(c => c.UserId)
.OnDelete(DeleteBehavior.Cascade);
});
}
}