Refactor. Add data layer

This commit is contained in:
rossmill76 committed 2026-03-06 11:05:01 +00:00
1 parent 3b7e4e6ec5
commit b6b794f0b4
82 files changed
+2930 -2811

No files matched your search

+39
View File
@@ -0,0 +1,39 @@
using System.ComponentModel.DataAnnotations;
namespace BudgetApp.Data.Entities;
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}";
}
@@ -0,0 +1,7 @@
using Microsoft.AspNetCore.Identity;
namespace BudgetApp.Data.Entities;
public class ApplicationUser : IdentityUser
{
}
+23
View File
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
namespace BudgetApp.Data.Entities;
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 bool IsDefault { get; set; }
public List<Transaction> Transactions { get; set; } = [];
}
+10
View File
@@ -0,0 +1,10 @@
namespace BudgetApp.Data.Entities;
public enum RecurrenceType
{
None,
Daily,
Weekly,
Monthly,
Yearly
}
+43
View File
@@ -0,0 +1,43 @@
using System.ComponentModel.DataAnnotations;
namespace BudgetApp.Data.Entities;
public class Salary
{
public int Id { get; set; }
[Required, MaxLength(200)]
public string Name { get; set; } = string.Empty;
public decimal Amount { get; set; }
public RecurrenceType RecurrenceType { get; set; } = RecurrenceType.Monthly;
public DateTime StartDate { get; set; } = DateTime.Today;
public int AccountId { get; set; }
public Account Account { get; set; } = default!;
public int? CategoryId { get; set; }
public Category? Category { get; set; }
[Required]
public string UserId { get; set; } = string.Empty;
public ApplicationUser User { get; set; } = default!;
public string GetPaydaySummary() => RecurrenceType switch
{
RecurrenceType.Weekly => $"Every week on {StartDate:dddd}",
RecurrenceType.Monthly => $"Monthly on the {GetOrdinal(StartDate.Day)}",
RecurrenceType.Yearly => $"Annually on {StartDate:MMMM d}",
_ => RecurrenceType.ToString()
};
private static string GetOrdinal(int day) => day switch
{
1 or 21 or 31 => $"{day}st",
2 or 22 => $"{day}nd",
3 or 23 => $"{day}rd",
_ => $"{day}th"
};
}
+35
View File
@@ -0,0 +1,35 @@
using System.ComponentModel.DataAnnotations;
namespace BudgetApp.Data.Entities;
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; }
public bool IsPaid { get; set; } = false;
public int? SalaryId { get; set; }
public Salary? Salary { get; set; }
}
@@ -0,0 +1,7 @@
namespace BudgetApp.Data.Entities;
public enum TransactionType
{
Income,
Expense
}