feat(ministry): add Ministry entity, seed (10), and read endpoint
This commit is contained in:
@@ -14,6 +14,7 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, string>
|
||||
public DbSet<GivingCategory> GivingCategories => Set<GivingCategory>();
|
||||
public DbSet<OfferingSession> OfferingSessions => Set<OfferingSession>();
|
||||
public DbSet<Giving> Givings => Set<Giving>();
|
||||
public DbSet<Ministry> Ministries => Set<Ministry>();
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder builder)
|
||||
{
|
||||
@@ -142,5 +143,12 @@ public class AppDbContext : IdentityDbContext<AppUser, AppRole, string>
|
||||
entity.HasOne(e => e.OfferingSession).WithMany(s => s.Givings)
|
||||
.HasForeignKey(e => e.OfferingSessionId).OnDelete(DeleteBehavior.Cascade);
|
||||
});
|
||||
|
||||
// ── Ministry ─────────────────────────────────────────────────────────
|
||||
builder.Entity<Ministry>(entity =>
|
||||
{
|
||||
entity.Property(e => e.Name_en).HasMaxLength(200).IsRequired();
|
||||
entity.Property(e => e.Name_zh).HasMaxLength(200);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,20 @@ public static class DbSeeder
|
||||
("Mission", "宣教奉獻", 5),
|
||||
];
|
||||
|
||||
private static readonly (string En, string Zh, int Sort)[] MinistrySeed =
|
||||
[
|
||||
("Administration", "行政", 1),
|
||||
("Preaching", "講道", 2),
|
||||
("Emcee", "司會", 3),
|
||||
("Worship", "敬拜", 4),
|
||||
("PPT/Media", "PPT/影音", 5),
|
||||
("Sound", "音控", 6),
|
||||
("Facility", "場地組", 7),
|
||||
("Hospitality", "招待", 8),
|
||||
("Children", "兒牧", 9),
|
||||
("Catering", "餐飲", 10),
|
||||
];
|
||||
|
||||
private static readonly (string Name, string Description)[] Roles =
|
||||
[
|
||||
("super_admin", "System administrator — full access"),
|
||||
@@ -66,6 +80,16 @@ public static class DbSeeder
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
public static async Task SeedMinistriesAsync(AppDbContext db)
|
||||
{
|
||||
foreach (var (en, zh, sort) in MinistrySeed)
|
||||
{
|
||||
if (!await db.Ministries.AnyAsync(m => m.Name_en == en))
|
||||
db.Ministries.Add(new Ministry { Name_en = en, Name_zh = zh, SortOrder = sort, IsActive = true });
|
||||
}
|
||||
await db.SaveChangesAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Seeds roles and (in Development) the default admin account.
|
||||
/// Called once on application startup after migrations have been applied.
|
||||
@@ -80,6 +104,7 @@ public static class DbSeeder
|
||||
|
||||
var db = services.GetRequiredService<AppDbContext>();
|
||||
await SeedGivingCategoriesAsync(db);
|
||||
await SeedMinistriesAsync(db);
|
||||
|
||||
if (env.IsDevelopment())
|
||||
await SeedAdminUserAsync(userManager);
|
||||
|
||||
Reference in New Issue
Block a user