feat(giving): seed default giving categories
This commit is contained in:
@@ -5,6 +5,15 @@ namespace ROLAC.API.Data;
|
|||||||
|
|
||||||
public static class DbSeeder
|
public static class DbSeeder
|
||||||
{
|
{
|
||||||
|
private static readonly (string En, string Zh, int Sort)[] GivingCategorySeed =
|
||||||
|
[
|
||||||
|
("Tithe", "什一奉獻", 1),
|
||||||
|
("General Offering", "一般奉獻", 2),
|
||||||
|
("Special Offering", "特別奉獻", 3),
|
||||||
|
("Building Fund", "建堂基金", 4),
|
||||||
|
("Mission", "宣教奉獻", 5),
|
||||||
|
];
|
||||||
|
|
||||||
private static readonly (string Name, string Description)[] Roles =
|
private static readonly (string Name, string Description)[] Roles =
|
||||||
[
|
[
|
||||||
("super_admin", "System administrator — full access"),
|
("super_admin", "System administrator — full access"),
|
||||||
@@ -37,6 +46,25 @@ public static class DbSeeder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static async Task SeedGivingCategoriesAsync(AppDbContext db)
|
||||||
|
{
|
||||||
|
foreach (var (en, zh, sort) in GivingCategorySeed)
|
||||||
|
{
|
||||||
|
if (!db.GivingCategories.Any(c => c.Name_en == en))
|
||||||
|
{
|
||||||
|
db.GivingCategories.Add(new GivingCategory
|
||||||
|
{
|
||||||
|
Name_en = en,
|
||||||
|
Name_zh = zh,
|
||||||
|
SortOrder = sort,
|
||||||
|
IsActive = true,
|
||||||
|
// Audit fields are stamped by AuditSaveChangesInterceptor on save.
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await db.SaveChangesAsync();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Seeds roles and (in Development) the default admin account.
|
/// Seeds roles and (in Development) the default admin account.
|
||||||
/// Called once on application startup after migrations have been applied.
|
/// Called once on application startup after migrations have been applied.
|
||||||
@@ -49,6 +77,9 @@ public static class DbSeeder
|
|||||||
|
|
||||||
await SeedRolesAsync(roleManager);
|
await SeedRolesAsync(roleManager);
|
||||||
|
|
||||||
|
var db = services.GetRequiredService<AppDbContext>();
|
||||||
|
await SeedGivingCategoriesAsync(db);
|
||||||
|
|
||||||
if (env.IsDevelopment())
|
if (env.IsDevelopment())
|
||||||
await SeedAdminUserAsync(userManager);
|
await SeedAdminUserAsync(userManager);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user