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

+39
View File
@@ -0,0 +1,39 @@
using System.ComponentModel.DataAnnotations;
namespace BudgetApp.Data;
public class Account
{
public int Id { get; set; }
[Required, MaxLength(100)]
public string Name { get; set; } = string.Empty;
public decimal CurrentBalance { get; set; }
[Required, MaxLength(7)]
public string Color { get; set; } = "#1b6ec2";
[Required, MaxLength(3)]
public string CurrencyCode { get; set; } = "GBP";
[Required]
public string UserId { get; set; } = string.Empty;
public ApplicationUser User { get; set; } = default!;
public List<Transaction> Transactions { get; set; } = [];
public static readonly Dictionary<string, string> CurrencySymbols = new()
{
["USD"] = "$", ["EUR"] = "€", ["GBP"] = "£", ["JPY"] = "¥",
["CAD"] = "C$", ["AUD"] = "A$", ["CHF"] = "CHF", ["CNY"] = "¥",
["INR"] = "₹", ["BRL"] = "R$", ["KRW"] = "₩", ["MXN"] = "MX$",
["SEK"] = "kr", ["NOK"] = "kr", ["DKK"] = "kr", ["NZD"] = "NZ$",
["ZAR"] = "R", ["PLN"] = "zł", ["TRY"] = "₺", ["THB"] = "฿"
};
public string GetSymbol() => CurrencySymbols.GetValueOrDefault(CurrencyCode, CurrencyCode);
public string FormatAmount(decimal amount) => $"{GetSymbol()}{amount:N2}";
}
+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);
});
}
}
+7
View File
@@ -0,0 +1,7 @@
using Microsoft.AspNetCore.Identity;
namespace BudgetApp.Data;
public class ApplicationUser : IdentityUser
{
}
+21
View File
@@ -0,0 +1,21 @@
using System.ComponentModel.DataAnnotations;
namespace BudgetApp.Data;
public class Category
{
public int Id { get; set; }
[Required, MaxLength(100)]
public string Name { get; set; } = string.Empty;
[MaxLength(10)]
public string Icon { get; set; } = string.Empty;
[Required]
public string UserId { get; set; } = string.Empty;
public ApplicationUser User { get; set; } = default!;
public List<Transaction> Transactions { get; set; } = [];
}
+45
View File
@@ -0,0 +1,45 @@
using System.ComponentModel.DataAnnotations;
namespace BudgetApp.Data;
public enum TransactionType
{
Income,
Expense
}
public enum RecurrenceType
{
None,
Daily,
Weekly,
Monthly,
Yearly
}
public class Transaction
{
public int Id { get; set; }
[Required, MaxLength(200)]
public string Description { get; set; } = string.Empty;
public decimal Amount { get; set; }
public DateTime Date { get; set; } = DateTime.Today;
public TransactionType Type { get; set; } = TransactionType.Expense;
public RecurrenceType RecurrenceType { get; set; } = RecurrenceType.None;
public DateTime? RecurrenceEndDate { get; set; }
public int? ParentTransactionId { get; set; }
public Transaction? ParentTransaction { get; set; }
public int AccountId { get; set; }
public Account Account { get; set; } = default!;
public int? CategoryId { get; set; }
public Category? Category { get; set; }
}