Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions Data/FinanceDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,23 @@ public FinanceDbContext(DbContextOptions<FinanceDbContext> options) : base(optio

public DbSet<Transaction> Transactions => Set<Transaction>();

public DbSet<SavingsInvestment> SavingsInvestments => Set<SavingsInvestment>();

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);

modelBuilder.Entity<Transaction>().Property(transaction => transaction.Amount).HasColumnType("decimal(18,2)");
modelBuilder.Entity<Transaction>().Property(transaction => transaction.Currency).HasMaxLength(3).HasDefaultValue("USD");
modelBuilder.Entity<SavingsInvestment>().Property(investment => investment.Amount).HasColumnType("decimal(18,2)");
modelBuilder.Entity<SavingsInvestment>().Property(investment => investment.Currency).HasMaxLength(3).HasDefaultValue("USD");
modelBuilder.Entity<SavingsInvestment>().Property(investment => investment.CashImpactType).HasMaxLength(30).HasDefaultValue("ExistingAsset");

var createdDate = new DateTime(2026, 6, 1, 0, 0, 0, DateTimeKind.Utc);
modelBuilder.Entity<Transaction>().HasData(
new Transaction { Id = 1, Type = "Income", Amount = 3000, Category = "Salary", Date = new DateTime(2026, 6, 1), Notes = "Monthly salary", CreatedDate = createdDate },
new Transaction { Id = 2, Type = "Expense", Amount = 25, Category = "Food", Date = new DateTime(2026, 6, 2), Notes = "Lunch", CreatedDate = createdDate },
new Transaction { Id = 3, Type = "Expense", Amount = 100, Category = "Shopping", Date = new DateTime(2026, 6, 3), Notes = "Clothes", CreatedDate = createdDate }
new Transaction { Id = 1, Type = "Income", Amount = 3000, Currency = "USD", Category = "Salary", Date = new DateTime(2026, 6, 1), Notes = "Monthly salary", CreatedDate = createdDate },
new Transaction { Id = 2, Type = "Expense", Amount = 25, Currency = "USD", Category = "Food", Date = new DateTime(2026, 6, 2), Notes = "Lunch", CreatedDate = createdDate },
new Transaction { Id = 3, Type = "Expense", Amount = 100, Currency = "USD", Category = "Shopping", Date = new DateTime(2026, 6, 3), Notes = "Clothes", CreatedDate = createdDate }
);
}

Expand All @@ -35,6 +41,14 @@ public override Task<int> SaveChangesAsync(CancellationToken cancellationToken =
}
}

foreach (var entry in ChangeTracker.Entries<SavingsInvestment>())
{
if (entry.State == EntityState.Added)
{
entry.Entity.CreatedDate = DateTime.UtcNow;
}
}

return base.SaveChangesAsync(cancellationToken);
}
}
132 changes: 132 additions & 0 deletions Migrations/20260606003948_AddSavingsInvestments.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 40 additions & 0 deletions Migrations/20260606003948_AddSavingsInvestments.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace FinanceProject.Migrations
{
/// <inheritdoc />
public partial class AddSavingsInvestments : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "SavingsInvestments",
columns: table => new
{
Id = table.Column<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
InvestmentType = table.Column<string>(type: "nvarchar(max)", nullable: false),
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Amount = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
Date = table.Column<DateTime>(type: "datetime2", nullable: false),
Notes = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
CreatedDate = table.Column<DateTime>(type: "datetime2", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_SavingsInvestments", x => x.Id);
});
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "SavingsInvestments");
}
}
}
149 changes: 149 additions & 0 deletions Migrations/20260606010152_AddCurrencyToFinanceEntries.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading