WIP
This commit is contained in:
1 parent
38067df8c3
commit
492d86db9e
30 files changed
+2473
-40
No files matched your search
@@ -13,6 +13,7 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
||||
public DbSet<Account> Accounts => Set<Account>();
|
||||
public DbSet<Transaction> Transactions => Set<Transaction>();
|
||||
public DbSet<Category> Categories => Set<Category>();
|
||||
public DbSet<Salary> Salaries => Set<Salary>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
@@ -45,6 +46,11 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
||||
.HasForeignKey(t => t.ParentTransactionId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
e.HasOne(t => t.Salary)
|
||||
.WithMany()
|
||||
.HasForeignKey(t => t.SalaryId)
|
||||
.OnDelete(DeleteBehavior.SetNull);
|
||||
|
||||
e.Property(t => t.Amount).HasColumnType("decimal(18,2)");
|
||||
});
|
||||
|
||||
@@ -55,5 +61,20 @@ public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
|
||||
.HasForeignKey(c => c.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
builder.Entity<Salary>(e =>
|
||||
{
|
||||
e.HasOne(s => s.User)
|
||||
.WithMany()
|
||||
.HasForeignKey(s => s.UserId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.HasOne(s => s.Account)
|
||||
.WithMany()
|
||||
.HasForeignKey(s => s.AccountId)
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
|
||||
e.Property(s => s.Amount).HasColumnType("decimal(18,2)");
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,7 @@ public class Category
|
||||
|
||||
public ApplicationUser User { get; set; } = default!;
|
||||
|
||||
public bool IsDefault { get; set; }
|
||||
|
||||
public List<Transaction> Transactions { get; set; } = [];
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace BudgetApp.Data;
|
||||
|
||||
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"
|
||||
};
|
||||
}
|
||||
@@ -42,4 +42,9 @@ public class Transaction
|
||||
|
||||
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; }
|
||||
}
|
||||
Reference in new issue
Block a user